1. 適用版本
操作方法在任何平台的Oracle GoldenGate - Version: 10.4.0.46 及以後的版本用有效。
2. 目標
實現向已經上線啟動並執行 Oracle GoldenGate 的環境中增加新的需要複製資料的表。
3. 方法
資料複製工具 Oracle GoldenGate 提供了兩種增加方法,我們這裡逐個介紹。
3.1 第一種:使用 handlecollision 參數
參數 handlecollision 應用於複製進程,就是目標庫上的 replicat 進程的配置。
如果在 replicat 上配置了參數,那麼複製進程工作時,將會對重複資料和丟失的資料做錯誤處理。
如果我們要求兩點的話,使用該參數是個絕佳選擇。
第一、 我們在加新表的 OGG 同步環境中時,能保證源庫上對此表不做任何 DML 操作,當然 DDL 操作也不能有。
第二、 我們加了新表後,目標庫上的資料不管,手工校正一次,發現不一致再手工處理也可以。
當然,在新加表的過程中,最好是源表不做任何操作。
以下步驟是ORACLE 官網提供的,這裡不做翻譯了。
i)using handlecollisions
----------------------------
1)stop the extract,pump and replicat
once the extract is stopped, wait for the pump to catch up before stopping it.
once the pump is stopped, wait for the replicat to catch up before stopping it.
2)include the tables that you need to add into the extract parameter file and save it
3)start the extract
4)include the tables that you need to add into the extract pump parameter file and save it
5)start the pump
6)do the initial load for the the new tables( ie you can take the export and import of the new tables that need to to added for replication from source the target database)
7)Wait for the initial load(export and import) to be completed and then include the tables that you need to add into the replicat parameter file with HANDLECOLLISIONS parameter
eg: MAP hr.dep, TARGET hr.dep, HANDLECOLLISIONS;
MAP hr.country, TARGET hr.country, HANDLECOLLISIONS;
6) start the replicat
7) once the lag becomes zero remove the HANDLECOLLISIONS from the replicat parameter file and restart the replicat
eg :-
MAP hr.dep, TARGET hr.dep;
MAP hr.country, TARGET hr.country;
note:- 4 and 5th step can be skipped if the pump is not configured.
3.2 第二種:不使用 handlecollision 參數
這種方法是通用的。因為在實際項目中,我們既不能保證源表的資料在操作 OGG 時無變化,由不能要求項目上接受資料差異或者丟失。
這種方法使用基於表的 SCN 方式同步差異資料。
在同步完成後,可以除掉關於 SCN 的同步配置。方法簡明扼要,很容易理解。
以下步驟是ORACLE 官網提供的,這裡也不做翻譯了。
ii)without using handlecollision
--------------------------------------
1) stop the extract,pump and replicat
once the extract is stopped, wait for the pump to catch up before stopping it.
once the pump is stopped, wait for the replicat to catch up before stopping it.
2)add the new table in extract parameter file and save it
3)start the extract
4)add the new table in extract pump parameter file and save it
5)start the extract pump
6)get the current SCN from the source database
eg:-
SQL> select current_scn from v$database;
CURRENT_SCN
------------------------
5343407
7) Check that there are no open DML transactions against the table. If there are open transactions, make sure that their starting SCN is higher than the one obtained in step 4) , i.e. 5343407
8)re-sync the the newly added table from source to target(using normal export/import).
Make sure to use FLASHBACK_SCN parameter for the export.
9) Add the table in the replicat parameter file including the below option( FILTER ( @GETENV ("TRANSACTION", "CSN") > <scn_number obtained from source db>) )as shown in the below example
eg:-
MAP source.test1, TARGET target.test1 ,FILTER ( @GETENV ("TRANSACTION", "CSN") > 5343407);
MAP source.test2, TARGET target.test2 ,FILTER ( @GETENV ("TRANSACTION", "CSN") > 5343407);
10)start the replicat
11)verify the tables on source and table and once the lag is zero remove the filter parameter from the replicat parameter file and restart.
4. 參數說明
HANDLECOLLISIONS | NOHANDLECOLLISIONS
Valid for Replicat
Use the HANDLECOLLISIONS and NOHANDLECOLLISIONS parameters to control whether or not Replicat tries to resolve duplicate-record and missing-record errors when applying SQL on the target. These errors can occur during an initial load, when data from source tables is being loaded to target tables while GoldenGate is replicating transactional changes that are being made to those tables. When GoldenGate applies the replicated changes after the load is finished, HANDLECOLLISIONS causes Replicat to overwrite duplicate records in the target tables and provides alternate handling of errors for missing records.
You can use HANDLECOLLISIONS and NOHANDLECOLLISIONS in the following ways:
● You can use either HANDLECOLLISIONS or NOHANDLECOLLISIONS at the root level of the parameter file to affect all MAP statements.
● You can use HANDLECOLLISIONS and NOHANDLECOLLISIONS as on-off switches for groups of tables to enable or disable error handling as needed. One remains in effect for all subsequent MAP statements until the other is encountered.
● You can use HANDLECOLLISIONS and NOHANDLECOLLISIONS within a MAP statement to enable and disable the functionality for a specific table. See page 204.
Any of the preceding methods can be combined. The use within a MAP statement overrides other settings. The use as a toggle overrides a global setting. For example, you could have a global NOHANDLECOLLISIONS setting, and then use HANDLECOLLISIONS within MAP statements to enable it only for certain tables.
更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12