浅析Oracle数据库集中方法
Oracle数据复制是实现分布式数据环境的一种技术,通过在不同的物理站点拷贝数据来建立分布式数据环境。它与分布式数据库不同,在
Oracle数据复制是实现分布式数据环境的一种技术,通过在不同的物理站点拷贝数据来建立分布式数据环境。它与分布式数据库不同,在分布式数据库中,虽然每个数据对象也对所有的站点可用,但是特定的数据对象只存在于一个特定的站点中。而数据复制实现所有的站点都有相同数据对象的可用拷贝。
在一个典型的分布式商业应用中经常需要把个地区的数据备份到总部的数据库中,一方面可以作为一种备份方式,另一方面也方便总部应用中的综合统计。这是Oracle数据复制中的简单应用,本文将以这样一个例子,讲述如何实现Oracle数据复制。
实际情况是,A公司总部在北京,有三个营业部分别位于上海(ORACLE.SHANGHAI.COM)、杭州(ORACLE.HANGZHOU.COM)和武汉(ORACLE.
WUHAN.COM)。三个营业部的软件系统相同,数据库结构也相同。现在需要把三个营业部的数据全部备份到总部的数据库中。
准备工作
在进行复制之前需要准备的东西很多,当然最基础就是网络必须畅通,之后需要收集一些复制环境的基本信息:
1.需要复制的数据库站点的数量
2.每个站点的Oracle版本号
3.每个需要复制的数据库的大小
4.每个数据库所使用的字符集
5.每个需要复制的数据所用的方案名
收集完环境信息,可以开始建立总部的集中数据库,集中数据库要求版本高于所有主战点的版本,最好所有的数据库都是用相同的字符集。建好库后为每个主站点的备份数据分别建一个表空间,表空间大于需要复制的数据量,至于预留以后的发展空间视实际情况而定。
为每个主站点的对应复制数据建立方案,如果各个主站点所使用的方案名不同,,在集中数据库站点分别建立名称相同的对应方案。否则为各主站点的复制数据分别建立相应的方案名。实际情况是后者,各营业部的数据库都是用Oracle的方案名,这里我们建立三个对应方
案:SHORACL、HZORACL和WHORACL。所有数据库的版本都是9i。
基本概念
复制之前先解释一下复制中的几个概念:
1.主站点(MaterSite):在复制过程中提供数据源的站点。如上图中的上海数据库站点。
2.实体化视图站点(MaterializedViewSite):实体化视图复制中的目标站点。如上图中的北京数据库站点。
3.多主体站点复制(MultimasterReplication):复制环境中的站点都是主站点,对复制的数据库对象有相同的管理权限。
4.实体化视图复制(MaterializedViewReplication):一个主体站点提供源复制对象,一个实体化视图站点拷贝主站点数据。
5.实体化视图(MaterializedView):在实体化视图站点为每个复制表或者视图建立一个对应的表保存相应的数据,该表只能通过Oracle的复制机制进行增删改数据的操作。
6.快速刷新、完全刷新和强制刷新:复制过程中的三种刷新方式。快速刷新只复制源数据对象的改变部分;完全刷新每次都拷贝一遍源数据对象;强制刷新是数据库的一个折衷方案,如果快速刷新失败则使用完全刷新。
7.主体组(MasterGroup):主体站点中被复制的源数据对象的集合。
8.实体化视图组(MaterializedViewSite):实体化视图站点中复制对象的集合。
9.实体化视图日志(MaterializedViewLog):实体化视图复制中使用快速刷新时记录主体源数据对象操作日志的表。
同步复制和异步复制就不解释了,本例采用每天一次的异步复制。
进行复制
配置好本地服务名分别为:上海站点:SH,杭州站点:HZ,武汉站点:WH,北京站点:BJ,进入没有登录的sqlplus,让我们开始复制!
一.设置主站点。
这里以上海主站点设置为例。
1.连接主站点,创建复制管理员并授予相应的权限,复制管理员是管理整个复制环境并创建复制对象的用户。只有数据管理员可以建立主体组和实体化视图组。
connectsystem/passwd@SH
createuserrepadminidentifiedbyrepadmin;
begin
dbms_repcat_admin.grant_admin_any_schema(
username=>’repadmin’);
end;
/
grantcommentanytabletoREPADMIN;
grantlockanytabletoREPADMIN;
后面的两个grant语句使复制管理员可以为任何表建立实体化视图日志。如果想改用户可以使用视图管理器,还需要下面的命令:
grantselectanydictionarytoREPADMIN;
2.注册传播方,传播方会将主体站点的延迟事务队列推入其他主体站点或者实体化视图站点。
begin
dbms_defer_sys.register_purpagator(username=>’repadmin’);
end;
3.调度清除作业,该作业会定时清除延迟事务队列并用传播方将延迟事务推入其他主体站点或者实体化视图站点。先更换用户:
disconnect;
connectrepadmin/repadmin@SH;
begin
dbms_defer_sys.schedule_purge(
next_date=>sysdate,interval=>’sysdate+1’,delay_seconds=>0);
end;
next_date:下一次执行日期,sysdate表示立即。
interval:间隔时段,sysdate+1表示间隔一天,sysdate+1/24表示间隔一小时
delay_seconds:当延迟队列没有延迟事件时停止被次清除操作的延迟时间。
4.为实体化视图站点建立复制代理。创建复制代理用户并授予视图接受方权限。复制代理是复制接收方连接主体站点的用户
disconnect;
connectsystem/passwd@SH;
createuserproxy_bjoracleidentifiedbyproxy_bjoracle;
begin
dbms_repcat_admin.register_user_repgroup(
user_name=>’proxy_bjoracle,
privilege_type=>’proxy_snapadmin’,list_of_gnames=>NULL);
end;
/
grantselect_catalog_roletoproxy_bjoracle;
5.创建主体组。
disconnect;
connectrepadmin/repadmin@SH;
begin
dbms_repcat.create_master_repgroup(gname=>’sh_rep’);
end;
/
6.向主体组中添加复制对象
a)添加表:
begin
dbms_repcat.create_master_repobject(
gname=>’sh_rep’,
type=>’TABLE’,
oname=>’CREDIT_CARD’
sname=>’SHORACL’
use_existing_object=>TRUE,
copy_rows=>TRUE);
end;
b)添加索引
begin
dbms_repcat.create_master_repobject(
gname=>’sh_rep’,
type=>’INDEX’,
oname=>’INDEX_CREDIT_CARD’
sname=>’SHORACL’
use_existing_object=>TRUE,
copy_rows=>FALSE);
end;
/
7.如果添加的表没有主键需要设置可以代替主键的列或者列的集合
begin
dbms_repcat.set_columns(
sname=>’SHORACL’,
oname=>’CREDIT_CARD’,
column_list=>’CREDIT_CARD_ID’);
end;
/
8.在主体组中的数据对象可以被复制之前,必须为他们生成复制支持。该方法为复制创建必要的触发器、包或者存储过程:
begin
dbms_repcat.generate_replication_support(
sname=>’SHORACL’,
oname=>’CREDIT_CARD’,
type=>’TABLE’,
min_communication=>TRUE);
end;
/
9.为快速刷新创建实体化视图日志:
creatematerializedviewlogonSHORACL.CREDIT_CARD;
如果是没有主键的表示用一下语句:
creatematerializedviewlogonSHORACL.CREDIT_CARDwith
rowidexcludingnewvalues;
10.启动复制:
begin
dbms_repcat.resume_master_activity(
name=>’sh_rep’);
end;
/

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.
