实战goldengate:安装配置+数据初始化+单向DML复制
1.安装软件 1.1 下载goldengate 1.2 设置ORACLE_HOME and ORACLE_SID等环境变量 确保安装的oracle实例设置了正确的ORACLE_HOME以及ORACLE_SID, 当ogg进程连接数据库时会引用它们。 1.3 设置共享库的环境变量 确保ggsci或其他ogg进程的正常运行需要正确设置共享库路径, 如果设置不正确在运行ggsci时会报错“./ggsci: error while loading shared libraries” export LD_LIBRARY_PATH=/opt/oracle/db_1/lib:$LD_LIBRARY_PATH /opt/oracle/db_1为oracle软件安装目录 1.4安装ogg 1.4.1 解压软件包 mkdir /opt/ogg/11.2 -p unzip ogg112101_fbo_ggs_Linux_x64_ora10g_64bit.zip tar -xvf fbo_ggs_Linux_x64_ora10g_64bit.tar 1.4.2 创建ogg工作目录 ./ggsci CREATE SUBDIRS EXIT
2.启用ogg的ddl复制 2.1 创建相应的用户以及表空间 sqlplus / as sysdba create tablespace ogg_tbs datafile '/opt/oracle/oradata/ogg1/ogg_tbs01.dbf' size 50M autoextend on; create user oggadmin identified by oracle default tablespace ogg_tbs quota unlimited on ogg_tbs; grant dba to oggadmin; 2.2 创建全局参数文件 ./ggsci EDIT PARAMS ./GLOBALS GGSCHEMA oggadmin EXIT 2.3 以sysdba角色运行相应脚本 @marker_setup.sql alter system set RECYCLEBIN=off; --运行ddl_setup前必须保证关闭数据库的回收站特性 @ddl_setup.sql @role_setup.sql GRANT GGS_GGSUSER_ROLE to oggadmin; @ddl_enable.sql NOTE:在源端ogg的ddl支持是默认关闭的,如果需要启用的话需在extract进程的参数文件中加入ddl参数; 在目标端ogg的ddl支持是默认开启的,如果有其他需求可以在replicat进程的参数文件中使用ddl参数来 过滤或或者忽略某些ddl操作。 3.配置ogg instance 3.1 配置mangager ./ggsci EDIT PARAMS MGR PORT 3809 DYNAMICPORTLIST 3800-3820 3.2 配置extract --源端 ./ggsci EDIT PARAMS ext1 EXTRACT ext1 USERID oggadmin, PASSWORD oracle EXTTRAIL /opt/ogg/11.2/dirdat/lt DDL INCLUDE MAPPED --让extract进程捕获ddl TABLE source.*; 3.3 配置data-pump --源端 ./ggsci EDIT PARAMS pump1 EXTRACT pump1 USERID oggadmin, PASSWORD oracle RMTHOST 10.10.2.118, MGRPORT 3809 RMTTRAIL /opt/ogg/11.2/dirdat/rt TABLE source.*; 3.4 配置replicat --目标端 3.4.1 创建checkpoint table ./ggsci dblogin userid oggadmin,password oracle add checkpointtable oggadmin.checkpoint EDIT PARAMS ./GLOBALS CHECKPOINTTABLE oggadmin.checkpoint 3.4.2 创建replicat参数文件 ./ggsci EDIT PARAMS rep1 REPLICAT rep1 USERID oggadmin, PASSWORD oracle DBOPTIONS SUPPRESSTRIGGERS DBOPTIONS DEFERREFCONST ASSUMETARGETDEFS DISCARDFILE /opt/ogg/11.2/disc.log MAP source..*, TARGET target.*; 4.配置oracle database for ogg 4.1 配置oracle database的日志模式 sqlplus / as sysdba shutdown immediate startup mount alter database archivelog; alter database open; ALTER DATABASE FORCE LOGGING; alter database add supplemental log data; select SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING,LOG_MODE from v$database; --查询数据库日志模式 4.2 创建测试用户以及测试表 sqlplus / as sysdba --源端 create user source identified by oracle; grant connect,resource to source; conn source/oracle create table test(id int,name varchar2(10)); begin for i in 1..3 loop insert into test values(i,'a'||i); end loop; commit; end; sqlplus / as sysdba --目标端 create user target identified by oracle; grant connect,resource to target; 4.3 启用表级别的补充日志 --源端 ./ggsci dblogin userid oggadmin,password oracle ADD TRANDATA source.* NOTE:执行上述操作时必须保证oracle中必须有source用户以及该用户下至少有一张表,否则回报如下错误: ERROR: No viable tables matched specification. 如果添加补充日志的表没有主键的话会报如下警告: WARNING OGG-00869 No unique key is defined for table 'TEST'. All viable columns will be used to represent the key,but may not guarantee uniqueness. KEYCOLS may be used to define the key. 5.配置ogg initial load 5.1 配置ogg instance 该配置已经在步骤3中完成 5.2 添加冲突处理 --目标端 如果在初始化加载时源库仍处于活动状态那么需要在replicat参数文件中添加如下参数: HANDLECOLLISIONS 5.3 关闭ddl同步 对于extract参数文件,去掉如下参数: DDL INCLUDE MAPPED 5.4 添加ogg进程 5.4.1 添加primary extract --源端 ./ggsci ADD EXTRACT ext1, TRANLOG, BEGIN NOW 5.4.2 添加local trail --源端 ./ggsci ADD EXTTRAIL /opt/ogg/11.2/dirdat/lt, EXTRACT ext1 5.4.3 添加data-pump extract --源端 ./ggsci ADD EXTRACT pump1, EXTTRAILSOURCE /opt/ogg/11.2/dirdat/lt 5.4.4 添加remote trail --源端 ./ggsci ADD RMTTRAIL /opt/ogg/11.2/dirdat/rt, EXTRACT pump1 5.4.5 添加replicat --目标端 ADD REPLICAT rep1, EXTTRAIL /opt/ogg/11.2/dirdat/rt NOTE:添加replicat进程是提示如下错误: ERROR: No checkpoint table specified for ADD REPLICAT. 这个错误貌似很奇怪,因为在之前的操作中已经添加了checkpoint表,你可以尝试退出ggsci会话然后 重新登录后再次添加即可,如果还是不行可以尝试重建checkpoint表 5.5 使用expdp/impdp初始化目标端 5.5.1 启动manager ./ggsci START MANAGER 5.5.2 启动primary extract --源端 ./ggsci START EXTRACT ext1 NOTE:这里启动extract进程时报如下错误: ERROR OGG-00303 Oracle GoldenGate Capture for Oracle, ext1.prm: USERID and PASSWORD required. 这里错误的原因是extract的参数文件中userid和password参数隔行了,这两个参数需要在同一行否则ogg会报上述错误 5.5.3 启动data-pump extract --源端 ./ggsci START EXTRACT pump1 5.5.4 使用expdp/impdp完成数据初始化 查询源库当前scn --源库 sqlplus / as sysdba select current_scn from v$database; CURRENT_SCN ----------- 606390 导出源库数据 --源库 expdp system/oracle directory=dump_dir dumpfile=source.dmp schemas=source flashback_scn=606390 模拟生产环境中源库的数据变化 --源库 sqlplus source/oracle select * from test; ID NAME ---------- ---------- 1 a1 2 a2 3 a3 delete test where id=1; commit; insert into test values(4,'a4'); insert into test values(5,'a5'); commit; update test set name='aa'||id where mod(id,2)=0; commit; SQL> select * from test; ID NAME ---------- ---------- 2 aa2 3 a3 4 aa4 5 a5 导入数据到目标库 --目标库 impdp system/oracle directory=dump_dir dumpfile=source.dmp remap_schema=source:target 查询当前目标库中的数据 --目标库 sqlplsu target/oracle SQL> select * from test; ID NAME ---------- ---------- 1 a1 2 a2 3 a3 5.5.5 确认replicat参数文件设置正确 --目标端 ./ggsci VIEW PARAMS rep1 NOTE:确认参数文件中有HANDLECOLLISIONS参数,如果没有使用以下命令添加 EDIT PARAMS rep1 5.5.6 指定scn启动repicat --目标端 ./ggsci start rep1, aftercsn 606390 NOTE:启动replicat进程报如下错误: OGG-00868 Oracle GoldenGate Delivery for Oracle, rep1.prm: ORA-06550: line 1, column 7: PLS-00201: identifier 'SYS.DBMS_STREAMS_ADM_UTL_INVOK' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored SQL BEGIN sys.dbms_streams_adm_utl_invok.SET_FOO_TRIGGER_SESSION_CONTXT (fire=>TRUE); END;. 解决办法是授予相应权限给ogg用户 sqlplus / as sysdba grant execute on DBMS_STREAMS_ADM_UTL_INVOK to oggadmin; 5.5.7 初始化完成后关闭HANDLECOLLISIONS --目标端 ./ggsci SEND REPLICAT rep1, NOHANDLECOLLISIONS 5.5.8 验证数据同步效果 --目标端 sqlplus target/oracle select * from test; ID NAME ---------- ---------- 2 aa2 3 a3 4 aa4 5 a5
正文到此结束