源端:qht115 目标端:qht131
单向复制已完成qht115到qht131的复制,现在的目的是将qht131的数据同步复制到qht115
昨天完成了og的配置,不过是单向的复制,而ogg更多的应用是双向复制
下面完成双向的复制 :
在安装单向复制的时候,源端 和目标端的ogg用户权限以及介质都已安装好,以下操作需要确保在源端和目标端都已执行
目前ogg的进程信息如下:
--qht115
GGSCI (qht115) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EORA_1 00:00:00 00:00:08
EXTRACT RUNNING PORA_1 00:00:00 00:00:02
--qht131
GGSCI (qht131) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING RORA_1 00:00:00 00:00:05
qht115有3个进程,一个manager,以及两个extract进程,分别是捕获进程和Pump数据到远端的进程;而qht131有一个manager进程以及一个复制进程。双向复制的过程就是新qht131当成源端,添加捕获进程和pump进程,qht115端当成目标端 ,添加复制进程就可以了。
1.在qht131端添加表级TRANDATA
GGSCI (qht131) 2> DBLOGIN USERID ogg, PASSWORD ogg
Successfully logged into database.
GGSCI (qht131) 3> add trandata l5m.ogg_test
Logging of supplemental redo data enabled for table L5M.OGG_TEST.
GGSCI (qht131) 4> info trandata l5m.ogg_test
Logging of supplemental redo log data is enabled for table L5M.OGG_TEST.
Columns supplementally logged for table L5M.OGG_TEST: OWNER, TABLE_NAME.
2.qht131端配置捕获进程
为了区别原来的单向复制,现在qht131到qht115端 的复制,进程号用eora_2,存放的文件也改为/u01/ogg/dirdat/bb。
GGSCI (qht131) 5> edit params eora_2
--添加以下内容
EXTRACT EORA_2
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
USERID ogg, PASSWORD ogg
EXTTRAIL /u01/ogg/dirdat/bb
TABLE l5m.ogg_test;
GGSCI (qht131) 6> ADD EXTRACT EORA_2,TRANLOG, BEGIN NOW
EXTRACT added.
GGSCI (qht131) 7> ADD EXTTRAIL /u01/ogg/dirdat/bb,EXTRACT EORA_2,MEGABYTES 5
EXTTRAIL added.
GGSCI (qht131) 8> START EXTRACT EORA_2
Sending START request to MANAGER ...
EXTRACT EORA_2 starting
GGSCI (qht131) 9> INFO EXTRACT EORA_2
EXTRACT EORA_2 Last Started 2018-09-18 11:25 Status RUNNING
Checkpoint Lag 00:00:44 (updated 00:00:06 ago)
Log Read Checkpoint Oracle Redo Logs
2018-09-18 11:24:38 Seqno 161, RBA 11606528
SCN 0.0 (0)
3.qht131端配置pump传输进程
设置远程的hostname以及文件格式
GGSCI (qht131) 12> EDIT PARAMS PORA_2
--加入以下内容
EXTRACT PORA_2
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
PASSTHRU
RMTHOST 172.17.61.115, MGRPORT 7809
RMTTRAIL /u01/ogg/dirdat/pb
TABLE l5m.ogg_test;
GGSCI (qht131) 13> ADD EXTRACT PORA_2,EXTTRAILSOURCE /u01/ogg/dirdat/bb
EXTRACT added.
GGSCI (qht131) 15> ADD RMTTRAIL /u01/ogg/dirdat/pb,EXTRACT PORA_2,MEGABYTES 5
RMTTRAIL added.
GGSCI (qht131) 16> START EXTRACT PORA_2
Sending START request to MANAGER ...
EXTRACT PORA_2 starting
GGSCI (qht131) 17> INFO EXTRACT PORA_2
EXTRACT PORA_2 Last Started 2018-09-18 12:42 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:58 ago)
Log Read Checkpoint File /u01/ogg/dirdat/bb000000
First Record RBA 0
4.配置qht115的replicate进程
GGSCI (qht115) 2> EDIT PARAMS RORA_2
--添加以下内容
REPLICAT RORA_2
SETENV (NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252)
USERID ogg, PASSWORD ogg
HANDLECOLLISIONS
ASSUMETARGETDEFS
DISCARDFILE /u01/ogg/dirrpt/RORA_bb.DSC, PURGE
MAP l5m.ogg_test, TARGET l5m.ogg_test;
GGSCI (qht115) 3> ADD REPLICAT RORA_2 exttrail /u01/ogg/dirdat/pb checkpointtable ogg.GGSCHKPT
REPLICAT added.
GGSCI (qht115) 4> START REPLICAT RORA_2
Sending START request to MANAGER ...
REPLICAT RORA_2 starting
GGSCI (qht115) 5> INFO REPLICAT RORA_2
REPLICAT RORA_2 Last Started 2018-09-18 13:41 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:06 ago)
Log Read Checkpoint File /u01/ogg/dirdat/pb000000
First Record RBA 0
5.查看两端现在的所有进程
进程名称以_1结尾的是qht115向qht131捕获,传输以及复制进程,以_2结尾的进程是qht131向qht115捕获,传输以及复制进程
GGSCI (qht131) 20> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EORA_2 00:00:00 00:00:06
EXTRACT RUNNING PORA_2 00:00:00 00:00:07
REPLICAT RUNNING RORA_1 00:00:00 00:00:06
GGSCI (qht115) 6> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EORA_1 00:00:00 00:00:08
EXTRACT RUNNING PORA_1 00:00:00 00:00:00
REPLICAT RUNNING RORA_2 00:00:00 00:00:01
6.验证:
qht115-->qht131 验证dml
qht115:
SQL> delete from l5m.ogg_test;
4242 rows deleted.
SQL> commit;
Commit complete.
SQL> select count(*) from l5m.ogg_test;
COUNT(*)
----------
0
qht131:
SQL> select count(*) from l5m.ogg_test;
COUNT(*)
----------
0
qht131-->qht115 验证dml
qht131:
SQL> insert into l5m.ogg_test select * from all_tables where owner='L5M';
246 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from l5m.ogg_test;
COUNT(*)
----------
246
qht115:
SQL> select count(*) from l5m.ogg_test;
COUNT(*)
----------
246
不过需要注意truncate由于不产生redo log,所以不支持ogg同步,
qht131:
SQL> truncate table l5m.ogg_test;
Table truncated.
qht115:
SQL> select count(*) from l5m.ogg_test;
COUNT(*)
----------
246
用了truncate之后两边的数据就不一致了,所以ogg在应用上面要控制不能用truncate命令。
另外,双向复制的时候也要避免同一时间两边的数据库更新同一笔数据,可以通过应用层面来做出划分,哪部分表由数据库A做更新,另一部分表由数据库B做更新。