oracle 11g golden gate(ogg)雙向複製的配置
源端:qht115 目標端:qht131
單向複製已完成qht115到qht131的複製,現在的目的是將qht131的資料同步複製到qht115
昨天完成了og的配置,不過是單向的複製,而ogg更多的應用是雙向複製
下面完成雙向的複製 :
在安裝單向複製的時候,源端 和目標端的ogg使用者許可權以及介質都已安裝好,以下操作需要確保在源端和目標端都已執行
- ogg使用者許可權
- 資料庫的force log以及附加日誌
- 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做更新。