配置Oracle 10g 双向流复制

2,547 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,547
On SlideShare
0
From Embeds
0
Number of Embeds
860
Actions
Shares
0
Downloads
58
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

配置Oracle 10g 双向流复制

  1. 1. 配置 Oracle 10g 双向流 复制 by Maclean.liu liu.maclean@gmail.com www.oracledatabase12g.com
  2. 2. About Mel Email:liu.maclean@gmail.coml Blog:www.oracledatabase12g.coml Oracle Certified Database Administrator Master 10gand 11gl Over 6 years experience with Oracle DBA technologyl Over 7 years experience with Linux technologyl Member Independent Oracle Users Groupl Member All China Users Groupl Presents for advanced Oracle topics: RAC,DataGuard, Performance Tuning and Oracle Internal.
  3. 3. 构建 Oracle 双向流复制是一个十分复杂的过程,我写这个文档的目的是尽量有条理地列出所需做的工作,帮助DBA 更有效的建设流复制环境。1.以 scott 模式为复制示例,一般只要在创建数据库时选择了安装 sample schema,都会存在该 scott 模式;至少保证源库中存在该 schema,以便可以初始化到目标库中。2.在源和目标 2 个数据库中创建 strmadmin 流管理用户,当然你也可以选用其他名字。同时在 2 个库中都要创建streams 使用的表空间,以便让 logmnr 使用它:CREATE TABLESPACE streams_tbs DATAFILE XXXXXX SIZE 100M REUSE AUTOEXTEND ON MAXSIZEUNLIMITED;/* 10g r2 中 logmnr 默认使用 SYSAUX 表空间 */exec DBMS_LOGMNR_D.SET_TABLESPACE (streams_tbs);/* 创建完表空间后,接着要创建 strmadmin 用户 */CREATE USER strmadmin IDENTIFIED BY strmadminDEFAULT TABLESPACE streams_tbsQUOTA UNLIMITED ON streams_tbs;GRANT DBA TO strmadmin;BEGINDBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(grantee => strmadmin,grant_privileges => true);END;//* 可以通过查询 dba_streams_administrator 视图检查用户是否正确授予流管理权限 */SQL> SELECT * FROM dba_streams_administrator;USERNAME LOC ACC------------------------------ --- ---MACLEAN YES YESSTRMADMIN YES YES
  4. 4. 3.在 2 边数据库中都需要设置合理的实例初始化参数,我们以 10g release2 为例:参数名与推荐值:_job_queue_interval = 1描述:job 的队列的扫描参数,默认为 5,即 5s 扫描一次出于何种考虑:设置较小的_job_queue_interval 有利于 propagation 作业如何设置:alter system set "_job_queue_interval"=1 scope=spfile;/* 注意 scope=spfile 的参数都需要重启实例方能生效 */参数名与推荐值:COMPATIBLE>= 10.2.0.0描述:数据库版本兼容性参数,以前介绍过,不再展开出于何种考虑:10g release2 的部分 Streams 新特性要求该参数至少为 10.2.0.0 或更高如何设置:只有从较低版本升级到 10g r2 的数据库需要设置该参数,alter system set compatible="10.2.0.0" scope=spfile;参数名与推荐值:GLOBAL_NAMES=true描述:指定是否要求 database link 名与数据库全局名一致,默认为 FALSE 也就是不需要一致出于何种考虑:帮助我们准确识别 database link 和数据库的关系,避免误操作如何设置:alter system set global_names=true scope=spfile;参数名与推荐值:job_queue_processes>4描述:指定了实例中 job 队列进程的数量(如 J000…J999).出于何种考虑:该参数控制了实例中能够并行运行的 job 的最大值,应设一个大于已配置的 propagations数量的值,同时也要考虑到可能还有其他数据库作业如何设置:alter system set job_queue_processes=15;参数名与推荐值:PARALLEL_MAX_SERVERS描述:指定了实例中最大并行进程的数量出于何种考虑:在 Streams 环境中,capture 进程和 apply 进程都会用到多个并行进程。设置该初始化参数为适当值(10*CPU#)以保证总是有足够的可用并行进程;每多一个 capture 或 apply 进程,则有必要为该参数+2 再加上加入的 capture 或 apply 进程的并行度 parallelism参数。如何设置:alter system set PARALLEL_MAX_SERVERS=40;参数名与推荐值:REMOTE_ARCHIVE_ENABLE描述:指定是否将归档日志传送到远程目的地出于何种考虑:只有 downstream capture 时会用到,不展开
  5. 5. 参数名与推荐值:SGA_MAX_SIZE描述:设置合理的 SGA 内存最大值出于何种考虑:常见参数,不展开参数名与推荐值:SGA_TARGET=0描述:disable 掉 10g 中的 Automatic Shared Memory Management.出于何种考虑:Oracle 推荐在 stream 环境中手动指定 streams_pool 和 shared_pool 的大小而不使用 10g 中的内存自动管理特性如何设置:alter system set sga_target=0;参数名与推荐值:调优 STREAMS_POOL_SIZE描述:为流池指定大小。流池包括了缓存的队列消息。此外,流池也会被用于并行 capture 和 apply 的内部通信。建议参考 V$STREAMS_POOL_ADVICE 视图的信息判断最佳大小,避免 spill 溢出出于何种考虑:该参数可以动态修改。若该参数归零则实例中 streams 相关的进程和作业都将无法运行。流池的大小受到以下因素的影响:1.capture 进程的并行度,每增加一个 capture 进程有必要为流池增加 10MB 的大小;此外当 capture 参数 PARALLELISM 大于 1 时,有必要为流池增加 10Mb*parallelism 的大小;举例来说,若某 capture 进程的并行度 parallelism 设置为 3,则需要为 Streams 池增加 30Mb。2.apply 进程的并行度,每增加一个 apply 进程有必要为 streams pool 增加 1MB;此外当 apply 进程的并行度大于 1 时,为 streams pool 增加 1Mb*parallelism 的大小;举例来说某 apply 进程的 parallelism 被设置为 5,则需要为 streams 池增加 5Mb。3.Logical Change Records(LCRS)被存储在 buffered queues 缓存队列中;适当增加 Streams pool 大小以适应源库和目标库上数据复制的数据量;Oracle 建议在低负载的数据库上最小设置 Streams pool 为 256Mb,而在活跃度高的 OLTP 环境中设置为 500Mb;通过 V$STREAMS_POOL_ADVISE 视图给出的建议进一步调整 Streams Pool 的大小到一个合理值以避免过多的缓存队列溢出到磁盘上。如何设置:select * from v$streams_pool_advice;/* 查询 v$streams_pool_advice 视图了解不同 streams_Pool_size 情况下的 estd_spill_time */alter system set streams_pool_size=500M;完成以上设置后建议重启实例以便让全部参数生效,2 边都要做。
  6. 6. 4.为 scott schema 下的对象创建追加日志(supplemental log),可以使用 dbms_capture_adm 包的prepare_schema_instantiation 存储过程为指定模式创建追加日志:NAME prepare_schema_instantiation()FUNCTION prepare a schema for instantiationPARAMETERS schema_name - (IN) the name of the schema to prepare supplemental_logging - (IN) supplemental logging level (NONE, KEYS, or ALL)NOTES KEYS means PRIMARY KEY, UNIQUE INDEX, and FOREIGN KEY levels combined.----------------------------------------------------------------------------*/ PROCEDURE prepare_schema_instantiation( schema_name IN VARCHAR2, supplemental_logging IN VARCHAR2 DEFAULT KEYS);/* 其默认 supplemental_logging 选项为 Key,即为 PRIMARY KEY, UNIQUE INDEX, and FOREIGN KEY 等键 创建 IMPLICIT 的追加日志 *//* 在 10g 或以上版本中 prepare_xxx_instantiation 存储过程也会隐式地创建追加日志组了(In versions 10g and above,prepare_xxx_instantiation procedure implicitly createssupplemenal log groups.Type of supplemental logging that is enabled implicitly using this command can be checkedusing the sql in the following link to the documentation. However, additionalsupplementallogging might need to be enabled depending on the requirements as mentioned above)。可以通过以下查询了解其追加日志组的属性:SELECT SCHEMA_NAME, SUPPLEMENTAL_LOG_DATA_PK log_pk, SUPPLEMENTAL_LOG_DATA_FK log_fk, SUPPLEMENTAL_LOG_DATA_UI log_ui, SUPPLEMENTAL_LOG_DATA_ALL log_all FROM DBA_CAPTURE_PREPARED_SCHEMAS;SCHEMA_NAME LOG_PK LOG_FK LOG_UI LOG_ALL------------------------------ -------- -------- -------- --------SCOTT IMPLICIT IMPLICIT IMPLICIT NO
  7. 7. 5.在源库上创建到目标库 strmadmin 用户的 database link:conn strmadmin/strmadmin;Connected.create database link clinicb.rh3.oracle.com connect to strmadmin identified by strmadminusing clinicb.rh3.oracle.com;Database link created./* 其中 clinicb.rh3.oracle.com 为目标库的全局数据库名,clinicb 为 db_name,rh3.oracle.com 为domain_name */在目标库上创建到源库 strmadmin 用户的 database link:conn strmadmin/strmadmin;Connected.create database link clinica.rh2.oracle.com connect to strmadmin identified by strmadminusing clinica.rh2.oracle.com;Database link created./* 其中 clinica.rh2.oracle.com 为源库的全局数据库名,clinica 为数据库名,rh2.oracle.com 为domain_name */6.在源库中分别为 capture 和 apply 创建队列 queue:begindbms_streams_adm.set_up_queue(queue_table => apply_srctab,queue_name => apply_src,queue_user => strmadmin);end;/PL/SQL procedure successfully completed.begindbms_streams_adm.set_up_queue(queue_table => capture_srctab,queue_name => capture_src,
  8. 8. queue_user => strmadmin);end;/PL/SQL procedure successfully completed.在目标库分别为 capture 和 apply 创建队列 queue:conn strmadmin/strmadmin@clinicb.rh3.oracle.comConnected.begindbms_streams_adm.set_up_queue(queue_table => apply_desttab,queue_name => apply_dest,queue_user => strmadmin);end;/PL/SQL procedure successfully completed.begindbms_streams_adm.set_up_queue(queue_table => capture_desttab,queue_name => capture_dest,queue_user => strmadmin);end;/PL/SQL procedure successfully completed.8.在源库 clinica 上为 scott 模式创建 capture process:conn strmadmin/strmadmin@clinica.rh2.oracle.comConnected.begindbms_streams_adm.add_schema_rules (schema_name => scott,streams_type => capture,streams_name => captures_src,
  9. 9. queue_name => capture_src,include_dml => true,include_ddl => true,inclusion_rule => true);end;/PL/SQL procedure successfully completed.9.在源库 clinica 上创建 apply process:conn strmadmin/strmadmin@clinica.rh2.oracle.comConnected.begindbms_streams_adm.add_schema_rules (schema_name => scott,streams_type => apply,streams_name => applys_src,queue_name => apply_src,include_dml => true,include_ddl => true,source_database => clinicb.rh3.oracle.com);end;/PL/SQL procedure successfully completed.10.若需要在源库中解决冲突处理,则有必要设置 conflict handlers,可以参考这个 streams 文件链接:http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14228/conflict.htm11.在源库 clinica 上配置 propagation process:conn strmadmin/strmadmin@clinica.rh2.oracle.comConnected.begindbms_streams_adm.add_schema_propagation_rules (
  10. 10. schema_name => scott,streams_name => prop_src_to_dest,source_queue_name => capture_src,destination_queue_name => apply_dest@clinicb.rh3.oracle.com,include_dml => true,include_ddl => true,source_database => clinica.rh2.oracle.com);end;/PL/SQL procedure successfully completed.12.在目标库 clinicb 上配置 capture process:conn strmadmin/strmadmin@clinicb.rh3.oracle.comConnected.begindbms_streams_adm.add_schema_rules (schema_name => scott,streams_type => capture,streams_name => captures_dest,queue_name => capture_dest,include_dml => true,include_ddl => true);end;/PL/SQL procedure successfully completed.13.在原库 clinica 上以目标库 clinicb 的 SCN 设置模式实例化 SCN(schema instantiation SCN):conn strmadmin/strmadmin@clinicb.rh3.oracle.comConnected.declarev_scn number;beginv_scn := dbms_flashback.get_system_change_number();dbms_apply_adm.set_schema_instantiation_scn@clinica.rh2.oracle.com(
  11. 11. source_schema_name => scott,source_database_name => clinicb.rh3.oracle.com,instantiation_scn => v_scn,recursive => true);end;/14.在目标库 clinicb 上配置 apply process:conn strmadmin/strmadmin@clinicb.rh3.oracle.comConnected.begindbms_streams_adm.add_schema_rules (schema_name => scott,streams_type => apply,streams_name => applys_dest,queue_name => apply_dest,include_dml => true,include_ddl => true,source_database => clinica.rh2.oracle.com);end;/PL/SQL procedure successfully completed.15.在目标库上配置 propagation process:conn strmadmin/strmadmin@clinicb.rh3.oracle.comConnected.begindbms_streams_adm.add_schema_propagation_rules (schema_name => scott,streams_name => prop_dest_to_src,source_queue_name => capture_dest,destination_queue_name => apply_src@clinica.rh2.oracle.com,include_dml => true,include_ddl => true,
  12. 12. source_database => clinicb.rh3.oracle.com);end;/PL/SQL procedure successfully completed.16.在目标库上初始化 scott 模式下的对象,有多种方法可以完成初始化。若对象均不存在,在可以使用export/import 导入导出工具完成 instantiation,若对象均已经存在,则直接使用dbms_apply_adm.set_schema_instantiation_scn 存储过程。我们的环境中 scott 模式已存在于目标库中:conn strmadmin/strmadmin@clinica.rh2.oracle.comConnected.declarev_scn number;beginv_scn := dbms_flashback.get_system_change_number();dbms_apply_adm.set_schema_instantiation_scn@clinicb.rh3.oracle.com(source_schema_name => scott,source_database_name => clinica.rh2.oracle.com,instantiation_scn => v_scn,recursive => true);end;/PL/SQL procedure successfully completed.17.若需要在目标库中解决冲突处理,则有必要设置 conflict handlers,可以参考这个 streams 文件链接:http://download-east.oracle.com/docs/cd/B19306_01/server. 102/b14228/conflict.htm18.在目标库中启动 capture 和 apply 进程:启动 Apply:/* 以 disable_on_erro 参数为N启动 apply 进程,即便遭遇错误,apply 也会继续处理 LCR */conn strmadmin/strmadmin@clinicb.rh3.oracle.comConnected.begin
  13. 13. dbms_apply_adm.set_parameter (apply_name => applys_dest,parameter => disable_on_error,value => N);end;/PL/SQL procedure successfully completed.exec dbms_apply_adm.start_apply (apply_name=> applys_dest);PL/SQL procedure successfully completed.在目标库中启动 capture process:exec dbms_capture_adm.start_capture (capture_name=>captures_dest);PL/SQL procedure successfully completed.19.同样的在源库启动 capture 和 apply 进程:begindbms_apply_adm.set_parameter (apply_name => applys_src,parameter => disable_on_error,value => N);end;/PL/SQL procedure successfully completed.exec dbms_apply_adm.start_apply (apply_name=> applys_src);PL/SQL procedure successfully completed.在源库启动 capture:exec dbms_capture_adm.start_capture (capture_name=>captures_src);PL/SQL procedure successfully completed.
  14. 14. 20.测试双向流复制是否成功:测试 ddl 语句:SQL> conn scott/tiger@clinica.rh2.oracle.comConnected.SQL> create table test_streams(t1 int);Table created.SQL> conn scott/tiger@clinicb.rh3.oracle.comConnected.SQL> desc test_streams;Name Null? Type----------------------------------------- -------- ----------------------------T1 NUMBER(38)SQL> create table anti_test(t1 int);Table created.SQL> conn scott/tiger@clinica.rh2.oracle.comConnected.SQL> desc anti_test;Name Null? Type----------------------------------------- -------- ----------------------------T1 NUMBER(38)/* ddl 语句双向复制成功 */测试 dml 语句:SQL> conn scott/tiger@clinica.rh2.oracle.comConnected.SQL> desc emp;Name Null? Type----------------------------------------- -------- ----------------------------EMPNO NOT NULL NUMBER(4)ENAME VARCHAR2(10)JOB VARCHAR2(9)MGR NUMBER(4)
  15. 15. HIREDATE DATESAL NUMBER(7,2)COMM NUMBER(7,2)DEPTNO NUMBER(2)SQL> update emp set sal=sal+50;14 rows updated.SQL> commit;Commit complete.SQL> select sum(sal) from emp; SUM(SAL)---------- 29725SQL> conn scott/tiger@clinicb.rh3.oracle.comConnected.SQL> select sum(sal) from emp; SUM(SAL)---------- 29725SQL> update emp set sal=sal+50;14 rows updated.SQL> commit;Commit complete.SQL> select sum(sal) from emp; SUM(SAL)---------- 30425
  16. 16. SQL> conn scott/tiger@clinica.rh2.oracle.comConnected.SQL> select sum(sal) from emp; SUM(SAL)---------- 30425/* dml 语句双向复制成功 */Reference:Oracle Streams Replication Example:http://prodlife.wordpress.com/2008/02/21/oracle-streams-replication-example/Oracle Streams: Recommendations for Heartbeat table:http://ksadba.wordpress.com/2008/07/02/oracle-streams-recommendations-for-heartbeat-table/© 2010, www.oracledatabase12g.com. 版权所有.文章允许转载,但必须以链接方式注明源地址,否则追求法律责任.

×