GoldenGate Active-Active Replication with Conflict Detection and Resolution (CDR) part 1

标题: GoldenGate Active-Active Replication with Conflict Detection and Resolution (CDR) part 1

链接: http://www.traveldba.com/archives/552


ogg active-active 冲突解决方法USEMAX ,这里描述两天同时update 看ogg 怎么处理数据
这里没用配置双活,使用同步一张表,在源端和目标端同时更新,看目标端的数据处理
ogg reolicat 进程配置文件
GGSCI (enmotech) 46> view params rpee
 
REPLICAT rpee
setenv ( NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
USERID goldengate,PASSWORD goldengate
SQLEXEC "ALTER SESSION SET CONSTRAINTS=DEFERRED"
REPORT AT 01:59
REPORTROLLOVER AT 02:00
--HANDLECOLLISIONS
DISCARDFILE ./dirrpt/rpee.dsc,PURGE
DISCARDROLLOVER AT 02:00
GETTRUNCATES
ASSUMETARGETDEFS
DYNAMICRESOLUTION
 
ALLOWNOOPUPDATES;
 
--This starts the macro
MACRO #exception_handler
BEGIN
, TARGET goldengate.exceptions
, COLMAP ( rep_name = "RPEE"
, table_name = @GETENV ("GGHEADER", "TABLENAME")
, errno = @GETENV ("LASTERR", "DBERRNUM")
, dberrmsg = @GETENV ("LASTERR", "DBERRMSG")
, optype = @GETENV ("LASTERR", "OPTYPE")
, errtype = @GETENV ("LASTERR", "ERRTYPE")
, logrba = @GETENV ("GGHEADER", "LOGRBA")
, logposition = @GETENV ("GGHEADER", "LOGPOSITION")
, committimestamp = @GETENV ("GGHEADER", "COMMITTIMESTAMP"))
, INSERTALLRECORDS
, EXCEPTIONSONLY;
END;
 
REPERROR (DEFAULT, EXCEPTION)
REPERROR (DEFAULT2, ABEND)
REPERROR (-1, EXCEPTION)
map ogg1.tgt, target ogg2.tgt1;
--冲突表
map ogg1.test1, target ogg2.test1;
MAP ogg1.test1 #exception_handler();
--MAP ogg1.test2, TARGET ogg2.test2,
MAP ogg1.test2, TARGET ogg2.test2,
comparecols( on update all, on delete all),
RESOLVECONFLICT (UPDATEROWEXISTS, (DEFAULT, USEMAX (last_mod_time))),
RESOLVECONFLICT (INSERTROWEXISTS, (DEFAULT, USEMAX (last_mod_time))),
RESOLVECONFLICT (DELETEROWEXISTS, (DEFAULT, OVERWRITE)),
RESOLVECONFLICT (UPDATEROWMISSING, (DEFAULT, OVERWRITE)),
RESOLVECONFLICT (DELETEROWMISSING, (DEFAULT, DISCARD));
--RESOLVECONFLICT (UPDATEROWEXISTS,(DEFAULT, IGNORE ));
--异常处理
MAP ogg1.test2, TARGET ogg2.test2_exception,
EXCEPTIONSONLY,
INSERTALLRECORDS
SQLEXEC (id qry, query "select name, phone, address, salary, balance, comment1, last_mod_time from ogg2.test2 where name = :p1", PARAMS(p1 = name )), 
COLMAP ( rep_name = "RPEE" 
,table_name = @GETENV ("GGHEADER", "TABLENAME") 
,errno = @GETENV ("LASTERR", "DBERRNUM") 
,dberrmsg = @GETENV ("LASTERR", "DBERRMSG") 
,optype = @GETENV ("LASTERR", "OPTYPE") 
,errtype = @GETENV ("LASTERR", "ERRTYPE") 
,logrba = @GETENV ("GGHEADER", "LOGRBA")
,logposition = @GETENV ("GGHEADER", "LOGPOSITION") 
,committimestamp = @GETENV ("GGHEADER", "COMMITTIMESTAMP")
,res_date = @DATENOW() 
,name_before = before.name
,phone_before = before.phone 
,address_before = before.address 
,salary_before = before.salary
,balance_before = before.balance 
,comment1_before = before.comment1
, LAST_MOD_TIME = before.last_mod_time
, name_current = qry.name
, phone_current = qry.phone
, address_current = qry.address
, salary_current = qry.salary
, balance_current = qry.balance
, comment1_current = qry.comment1
, last_mod_time_current = qry.last_mod_time
);
map ogg1.test3, target ogg2.test3,COLMAP (USEDEFAULTS);
两边同时增加两条数据
SQL> col name FOR a8
SQL> col ADDRESS FOR a15
SQL> col COMMENT1 FOR a20
 
SQL> SELECT * FROM ogg1.test2;
 
NAME     PHONE      ADDRESS             SALARY    BALANCE COMMENT1             LAST_MOD_TIME
-------- ---------- --------------- ---------- ---------- -------------------- ---------------------------------------------------------------------------
Mary     1234567890 Oracle Pkwy            100        100 ccc                  04-FEB-13 12.00.00.000000 AM
Mary1    1234567890 Oracle Pkwy            100        100 ccc                  04-FEB-13 12.00.00.000000 AM
 
SQL> SELECT * FROM ogg2.test2;
 
NAME     PHONE      ADDRESS             SALARY    BALANCE COMMENT1             LAST_MOD_TIME
-------- ---------- --------------- ---------- ---------- -------------------- ---------------------------------------------------------------------------
Mary     1111111    Ralston                300        600 bbb                  03-FEB-13 12.00.00.000000 AM
Mary1    1111111    Ralston                300        600 bbb                  03-FEB-13 12.00.00.000000 AM
两边在同一时间更新,看ogg2.test2的数据处理
ogg1.test2
SQL> UPDATE test2 SET BALANCE=500,LAST_MOD_TIME=sysdate WHERE name='Mary';
 
1 ROW updated.
 
SQL> commit;
 
Commit complete.
 
SQL> col name FOR a8
SQL> col ADDRESS FOR a15
SQL> col COMMENT1 FOR a20
SQL> /
 
NAME     PHONE      ADDRESS             SALARY    BALANCE COMMENT1             LAST_MOD_TIME
-------- ---------- --------------- ---------- ---------- -------------------- ---------------------------------------------------------------------------
Mary     1234567890 Oracle Pkwy            100        500 ccc                  18-OCT-13 09.10.48.000000 PM
Mary1    1234567890 Oracle Pkwy            100        100 ccc                  04-FEB-13 12.00.00.000000 AM
 
SQL> UPDATE ogg1.test2 SET BALANCE=400,LAST_MOD_TIME=sysdate WHERE name='Mary' AND BALANCE=500;
 
1 ROW updated.
 
SQL> commit;
 
Commit complete.
 
SQL> SELECT * FROM ogg1.test2;
 
NAME     PHONE      ADDRESS             SALARY    BALANCE COMMENT1             LAST_MOD_TIME
-------- ---------- --------------- ---------- ---------- -------------------- ---------------------------------------------------------------------------
Mary     1234567890 Oracle Pkwy            100        400 ccc                  18-OCT-13 09.18.35.000000 PM
Mary1    1234567890 Oracle Pkwy            100        100 ccc                  04-FEB-13 12.00.00.000000 A
ogg2.test2
SQL> UPDATE test2 SET BALANCE=700,LAST_MOD_TIME=sysdate WHERE name='Mary';
 
1 ROW updated.
 
SQL> commit;
 
Commit complete.
 
SQL> SELECT * FROM ogg2.test2;
 
NAME     PHONE      ADDRESS             SALARY    BALANCE COMMENT1             LAST_MOD_TIME
-------- ---------- --------------- ---------- ---------- -------------------- ---------------------------------------------------------------------------
Mary     1111111    Ralston                300        700 bbb                  18-OCT-13 09.10.40.000000 PM
Mary1    1111111    Ralston                300        600 bbb                  03-FEB-13 12.00.00.000000 AM
 
SQL> UPDATE test2 SET BALANCE=800,LAST_MOD_TIME=sysdate WHERE name='Mary' AND BALANCE=700;
 
1 ROW updated.
 
SQL> commit;
 
Commit complete.
 
SQL> SELECT * FROM ogg2.test2;
 
NAME     PHONE      ADDRESS             SALARY    BALANCE COMMENT1             LAST_MOD_TIME
-------- ---------- --------------- ---------- ---------- -------------------- ---------------------------------------------------------------------------
Mary     1111111    Ralston                300        800 bbb                  18-OCT-13 09.19.06.000000 PM
Mary1    1111111    Ralston                300        600 bbb                  03-FEB-13 12.00.00.000000 AM
从上面可以看出ogg采用了LAST_MOD_TIME字段的最大值来更新数据
看下ogg的冲突解决记录
GGSCI (enmotech) 41> stats rpee reportcdr
 
Sending STATS request to REPLICAT RPEE ...
 
Start of Statistics at 2013-10-18 21:26:49.
 
Replicating from OGG1.TEST2 to OGG2.TEST2:
 
*** Total statistics since 2013-10-18 20:40:17 ***
        Total inserts                                      2.00
        Total updates                                      0.00
        Total deletes                                      4.00
        Total discards                                     4.00
        Total operations                                   6.00
        Total CDR conflicts                                6.00
        CDR resolutions succeeded                          2.00
        CDR resolutions failed                             2.00
        CDR UPDATEROWMISSING conflicts                     2.00
        CDR DELETEROWMISSING conflicts                     2.00
 
*** Daily statistics since 2013-10-18 20:40:17 ***
        Total inserts                                      2.00
        Total updates                                      0.00
        Total deletes                                      4.00
        Total discards                                     4.00
        Total operations                                   6.00
        Total CDR conflicts                                6.00
        CDR resolutions succeeded                          2.00
        CDR resolutions failed                             2.00
        CDR UPDATEROWMISSING conflicts                     2.00
        CDR DELETEROWMISSING conflicts                     2.00
 
*** Hourly statistics since 2013-10-18 21:00:00 ***
 
        No database operations have been performed.
 
*** Latest statistics since 2013-10-18 20:40:17 ***
        Total inserts                                      2.00
        Total updates                                      0.00
        Total deletes                                      4.00
        Total discards                                     4.00
        Total operations                                   6.00
        Total CDR conflicts                                6.00
        CDR resolutions succeeded                          2.00
        CDR resolutions failed                             2.00
        CDR UPDATEROWMISSING conflicts                     2.00
        CDR DELETEROWMISSING conflicts                     2.00


你可能感兴趣的:(Oracle,OGG)