oracle 11g 同库搭建 ogg-进阶2 本文为进阶2,比上一篇进阶1多了源库实施生成数据,主要做记录,其中配置若有误请见谅!!!
此次为了方便就同机搭建,所以mgr端口不同,如果不同机搭建,mgr端口可以一致
搭建环境
name
version
操作系统
CentOS Linux release 7.6.1810 (Core)
数据库版本
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
ogg版本
Oracle GoldenGate Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO Linux, x64, 64bi
1 2 3 4 5 6 7 8 1.搭建goldengate,开启mgr、extract、pump,不开启replicate 2.查询当前scn(当前事务的最小start_time>extract时间) 3.按scn导出源库schema数据(exp/expdp) 4.目标库导入数据 5.检查目标trail文件中scn对应的序号和rba 6.修改并开启rba进程 7.检查、测试同步
1. 新建ogg用户 1 2 3 4 5 6 7 8 9 10 11 12 13 groupadd ogg useradd -g ogg -G oinstall,dba ogg echo "oracle" | passwd --stdin oraclesu - ogg rz mkdir sogg togg mkdir sogg/temp unzip V34339-01.zip tar -xf fbo_ggs_Linux_x64_ora11g_64bit.tar -C sogg/ tar -xf fbo_ggs_Linux_x64_ora11g_64bit.tar -C togg/
2. 配置ogg环境变量 1 2 3 4 5 6 7 8 9 export TMP=/tmpexport ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1export ORACLE_SID=SRMexport PATH=/u01/app/oracle/product/11.2.0/dbhome_1/bin:/usr/sbin:/u01/app/oracle/product/11.2.0/dbhome_1/OPatch:/usr/local /sbin:/usr/local /bin:/usr/sbin:/usr/bin:/root/binexport LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/dbhome_1/lib:/lib:/usr/libexport CLASSPATH=/u01/app/oracle/product/11.2.0/dbhome_1/JRE:/u01/app/oracle/product/11.2.0/dbhome_1/jlib:/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/jlibexport NLS_LANG=AMERICAN_AMERICA.UTF8export LC_ALL=en_US.UTF-8
3. source和target都准备 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 sqlplus / as sysdba set lin 200 pages 30000 alter system set enable_goldengate_replication = true ;create tablespace ogg_tbs datafile '/u01/app/oracle/oradata/SRM/ogg_tbs01.dbf' size 100 M autoextend on ;create user ogg identified by oracle default tablespace ogg_tbs;grant dba to ogg; drop user yg1 cascade ;drop user yg2 cascade ;set lin 200 pages 30000 create tablespace test_tbs datafile '/u01/app/oracle/oradata/SRM/test_tbs01.dbf' size 10 M autoextend on ;create user yg1 identified by oracle default tablespace test_tbs;create user yg2 identified by oracle default tablespace test_tbs;grant dba to yg1,yg2;conn yg1/oracle create table t1 as select * from dba_tables;create table t2 as select * from dba_tables;create table t3 (id int ,t_date date );declare job_num number ; begin dbms_job.submit( job => job_num, what => 'insert into t3 values(dbms_random.value*10, sysdate);' , next_date => sysdate , interval =>'sysdate+1/24/60/6' ); commit ; end ;/ alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss' ;select job from user_jobs;select * from t3;alter database archivelog ;alter database force logging ;alter database add supplemental log data ;select NAME ,OPEN_MODE,FORCE_LOGGING,SUPPLEMENTAL_LOG_DATA_MIN from v$database ;alter system set UNDO_RETENTION = 10800 ;alter system set OPEN_CURSORS = 10000 ;@/home/ogg/sogg/marker_setup.sql @/home/ogg/sogg/ddl_setup.sql @/home/ogg/sogg/role_setup.sql @/home/ogg/sogg/ddl_enable.sql
4. 创建 GoldenGate 的工作目录 1 2 3 4 5 6 7 cd /home/ogg/sogg/./ggsci create subdirs cd /home/ogg/togg/./ggsci create subdirs
5. 源端添加checkpointtable 1 2 3 4 5 6 7 8 9 10 11 cd /home/ogg/sogg/./ggsci EDIT PARAMS ./GLOBALS ----------------------------------------- GGSCHEMA ogg CHECKPOINTTABLE ogg.ggschkpt1 ----------------------------------------- exit ./ggsci DBLOGIN USERID ogg, PASSWORD oracle ADD CHECKPOINTTABLE
6. 目标添加checkpointtable 1 2 3 4 5 6 7 8 9 10 11 cd /home/ogg/togg/./ggsci EDIT PARAMS ./GLOBALS ----------------------------------------- GGSCHEMA ogg CHECKPOINTTABLE ogg.ggschkpt2 ----------------------------------------- exit ./ggsci DBLOGIN USERID ogg, PASSWORD oracle ADD CHECKPOINTTABLE
7. 源配置mgr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 EDIT PARAMS MGR ----------------------------------------- PORT 7809 DYNAMICPORTLIST 7800-8000 AUTOSTART EXTRACT * AUTORESTART EXTRACT *,WAITMINUTES 2,RETRIES 5, RESETMINUTES 5 USERID ogg, PASSWORD oracle PURGEOLDEXTRACTS /home/oracle/sogg/dirdat,USECHECKPOINTS,MINKEEPDAYS 1 PURGEDDLHISTORY MINKEEPDAYS 3,MAXKEEPDAYS 7,FREQUENCYMINUTES 30 PURGEMARKERHISTORY MINKEEPDAYS 3,MAXKEEPDAYS 7 LAGREPORTHOURS 1 LAGINFOMINUTES 30 LAGCRITICALMINUTES 45 -----------------------------------------
8. 目标配置mgr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 EDIT PARAMS MGR ----------------------------------------- PORT 8809 DYNAMICPORTLIST 8800-9000 AUTOSTART EXTRACT * AUTORESTART EXTRACT *, WAITMINUTES 2, RESETMINUTES 5, RETRIES 5 USERID ogg, PASSWORD oracle PURGEOLDEXTRACTS /home/ogg/togg/dirdat, USECHECKPOINTS, MINKEEPDAYS 3 PURGEDDLHISTORY MINKEEPDAYS 3,MAXKEEPDAYS 7,FREQUENCYMINUTES 30 PURGEMARKERHISTORY MINKEEPDAYS 3,MAXKEEPDAYS 7 LAGREPORTHOURS 1 LAGINFOMINUTES 30 LAGCRITICALMINUTES 45 ----------------------------------------- start mgr info mgr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 EDIT PARAMS EORA_1 ----------------------------------------- EXTRACT EORA_1 SETENV (ORACLE_SID="SRM" ) SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) USERID ogg, PASSWORD oracle GETTRUNCATES REPORTCOUNT EVERY 1 MINUTES,RATE NUMFILES 5000 DISCARDROLLOVER AT 3:00 WARNLONGTRANS 2h,CHECKINTERVAL 3m DYNAMICRESOLUTION DBOPTIONS ALLOWUNUSEDCOLUMN IGNOREAPPLOPS IGNOREREPLICATES FETCHOPTIONS NOUSESNAPSHOT FETCHOPTIONS FETCHPKUPDATECOLS DISCARDFILE /home/ogg/sogg/dirrpt/eora_a.dsc,APPEND,MEGABYTES 1000 EXTTRAIL /home/ogg/sogg/dirdat/aa,MEGABYTES 100 TRANLOGOPTIONS DBLOGREADER TRANLOGOPTIONS EXCLUDEUSER ogg CACHEMGR CACHEDIRECTORY /home/ogg/sogg/temp DDL INCLUDE ALL DDLOPTIONS ADDTRANDATA,REPORT TABLE yg1.*; ----------------------------------------- ADD EXTRACT EORA_1, TRANLOG, BEGIN NOW, threads 1 info extract * ADD EXTTRAIL /home/ogg/sogg/dirdat/aa, EXTRACT EORA_1, MEGABYTES 100 start extract eora_1 info eora_1
10. 配置 Pump 进程 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 EDIT PARAMS PORA_1 ----------------------------------------- EXTRACT PORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) PASSTHRU NUMFILES 5000 RMTHOST yg-ocm, MGRPORT 8809,COMPRESS RMTTRAIL /home/ogg/togg/dirdat/pa DYNAMICRESOLUTION TABLE yg1.*; ----------------------------------------- ADD EXTRACT PORA_1, EXTTRAILSOURCE /home/ogg/sogg/dirdat/aa ADD RMTTRAIL /home/ogg/togg/dirdat/pa, EXTRACT PORA_1, MEGABYTES 100 START EXTRACT PORA_1 info all
11. 配置目标端的 Replicat 进程 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 EDIT PARAMS RORA_1 ----------------------------------------- REPLICAT RORA_1 SETENV (NLS_LANG=AMERICAN_AMERICA.UTF8) USERID ogg, PASSWORD oracle SQLEXEC "alter session set constraints=deferred" DBOPTIONS DEFERREFCONST GETTRUNCATES REPORT AT 06:00 REPORTCOUNT EVERY 1 MINUTES,RATE REPORTROLLOVER AT 02:00 REPERROR DEFAULT,ABEND NUMFILES 5000 DISCARDFILE ./dirrpt/rep_a.dsc,APPEND,MEGABYTES 1024m DISCARDROLLOVER AT 02:00 GROUPTRANSOPS 1000 HANDLECOLLISIONS ASSUMETARGETDEFS ALLOWNOOPUPDATES DDLERROR DEFAULT IGNORE DDL INCLUDE MAPPED DDLOPTIONS REPORT MAP yg1.*, TARGET yg2.*; ----------------------------------------- add replicat RORA_1, exttrail /home/ogg/togg/dirdat/pa
12. 源库scn数据手动导入到目标库 1 2 3 4 5 6 7 8 9 10 11 12 sqlplus system/oracle create or replace directory expdp_dir as '/home/oracle' ;select current_scn from v$database ;exit expdp system/oracle schemas=yg1 directory=expdp_dir dumpfile=yg-test.dmp nologfile=y FLASHBACK_SCN=1732604 REUSE_DUMPFILES=y exclude=job sqlplus sytem/oracle create or replace directory impdp_dir as '/home/oracle' ;exit impdp system/oracle schemas=yg1 directory=impdp_dir dumpfile=yg-test.dmp nologfile=y remap_schema=yg1:yg2
13. 启动REPLICAT RORA_1 进程 1 2 3 start replicat RORA_1,aftercsn 1732604 info all
14. 测试数据同步 1 2 3 4 5 6 sqlplus yg1/oracle select * from t3;sqlplus yg2/oracle select * from tab;select * from t3;
至此,ogg-进阶2就搭建完成了,是不是复杂了很多感觉,别灰心,从前面简单的开始,慢慢来,哈哈
1 2 其中个别参数我也还没理解,我们老师上课mgr是没有加入userid参数的,但是我的purge历史数据报错,网上说是需要指定登录数据库清理历史数据,果然加上就没报错,我也不确定是不是一定需要。 总之出问题多看 ./ggserr.log 就行了,从简单的开始,一步一步来就行了。