ITPub博客

首页 > 数据库 > Oracle > 关于goldengate无主键表的update的同步

关于goldengate无主键表的update的同步

原创 Oracle 作者:yangsir1 时间:2015-10-11 17:35:20 0 删除 编辑

关于goldengate无主键表的update的同步(源端和目的端列数不一样多)            

源端:windows 2003 sql2005 sp3
目的端:rhel5.3 x64bit, db2 v9.7 x64bit

源端表结构:(无主键无唯一索引)
CREATE TABLE [lc0019999].[KCCKD2](
[KCCKD2_PJLX] [char](1) NOT NULL,
[KCCKD2_LSBH] [varchar](10) NOT NULL,
[KCCKD2_FLBH] [varchar](10) NOT NULL,
[KCCKD2_WLBH] [varchar](30) NOT NULL,
[KCCKD2_TSKC] [char](1) NOT NULL DEFAULT (' '),
[KCCKD2_XGDX] [varchar](30) NOT NULL DEFAULT (' '),
[KCCKD2_DDLS] [varchar](20) NULL DEFAULT (' '),
[KCCKD2_DDFL] [varchar](10) NULL DEFAULT (' '),
[KCCKD2_TDLS] [varchar](10) NULL DEFAULT (' '),
[KCCKD2_WTLS] [varchar](10) NULL DEFAULT (' '),
[KCCKD2_WTFL] [varchar](10) NULL DEFAULT (' '),
[KCCKD2_QLLS] [varchar](10) NULL DEFAULT (' '),
[KCCKD2_QLFL] [varchar](10) NULL DEFAULT (' '),
[KCCKD2_HXSL] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_HXFSL1] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_HXFSL2] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_HXDJ] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_HXJE] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_GZZX] [varchar](30) NULL,
[KCCKD2_PCH] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_HWBH] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_ZYX1] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_ZYX2] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_ZYX3] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_ZYX4] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_ZYX5] [varchar](20) NOT NULL DEFAULT (' '),
[KCCKD2_WLZT] [varchar](4) NOT NULL DEFAULT (' '),
[KCCKD2_WLBZ] [varchar](8) NOT NULL DEFAULT (' '),
[KCCKD2_QLSL] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_SL] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_DJ] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_JE] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_FSL1] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_FSL2] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_TDFL] [varchar](10) NULL,
[KCCKD2_XEFL] [varchar](10) NULL,
[KCCKD2_BZBH] [varchar](20) NULL,
[KCCKD2_GXBH] [varchar](10) NULL,
[KCCKD2_ZJZT] [char](1) NULL,
[KCCKD2_ZJJL] [char](1) NULL,
[KCCKD2_CLFS] [char](1) NULL,
[KCCKD2_ZJWC] [char](1) NULL,
[KCCKD2_JSSL] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_BGDH] [varchar](20) NULL,
[KCCKD2_BZ] [varchar](200) NULL,
[KCCKD2_C1] [varchar](100) NULL,
[KCCKD2_C2] [varchar](100) NULL,
[KCCKD2_C3] [varchar](100) NULL,
[KCCKD2_C4] [varchar](100) NULL,
[KCCKD2_C5] [varchar](100) NULL,
[KCCKD2_U1] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_U2] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_U3] [dbo].[u001] NOT NULL DEFAULT ((0)),
[KCCKD2_FSL3] [dbo].[u001] NULL DEFAULT ((0)),
[KCCKD2_FQLSL] [dbo].[u001] NULL DEFAULT ((0)),
[KCCKD2_CXESL] [dbo].[u001] NULL DEFAULT ((0)),
[KCCKD2_CBBZ] [char](1) NULL,
[KCCKD2_THDZSL] [dbo].[u001] NULL DEFAULT ((0)),
[KCCKD2_THDJCSL] [dbo].[u001] NULL DEFAULT ((0)),
[KCCKD2_SCSQLS] [varchar](10) NULL,
[KCCKD2_SCSQFL] [varchar](10) NULL,
[KCCKD2_SCDDLS] [varchar](20) NULL
) ON [PRIMARY]


目的端表结构:(无主键无唯一索引)

除了上述列之外,比源端多了5列,这5列是用于bi目的的标识列.


需要在源端的ext和datapump进程的参数文件中,定义keycols,keycols包含源端所有的列。
需要在目的端的rep进程的参数文件中,定义keycols,keycols包含源端所有的列,keycols用作update的"伪主键".

若是不定义keycols,目的端的rep进程,在启动时会报错:

***********************************************************************
** Run Time Messages **
***********************************************************************

Opened trail file /db2/ggv11db2/dirdat/bb000008 at 2011-05-25 18:22:02

MAP resolved (entry LC0019999.KCCKD2):
map LC0019999.KCCKD2, target GGSCHEMA.KCCKD2, COLMAP (USEDEFAULTS, ETL_FL_NM =1, BUSI_DATE = @COLSTAT (NULL), PPN_TMSTAMP = @COLSTAT (NULL), OPERTYPE = @GETENV ("GGHEADER", "OPTYPE") , MODIFY_DATATIME = @GETENV ("GGHEADER", "COMMITTIMESTAMP"));
Using the following default columns with matching names:
KCCKD2_PJLX=KCCKD2_PJLX, KCCKD2_LSBH=KCCKD2_LSBH, KCCKD2_FLBH=KCCKD2_FLBH, KCCKD2_WLBH=KCCKD2_WLBH, KCCKD2_TSKC=KCCKD2_TSKC, KCCKD2_XGDX=KCCKD2_XGDX, KCCKD2_DDLS=KCCKD2_DDLS, KCCKD2_DDFL=KCCKD2_DDFL, KCCKD2_TDLS=KCCKD2_TDLS, KCCKD2_WTLS=KCCKD2_WTLS, KCCKD2_WTFL=KCCKD2_WTFL, KCCKD2_QLLS=KCCKD2_QLLS, KCCKD2_QLFL=KCCKD2_QLFL, KCCKD2_HXSL=KCCKD2_HXSL, KCCKD2_HXFSL1=KCCKD2_HXFSL1, KCCKD2_HXFSL2=KCCKD2_HXFSL2, KCCKD2_HXDJ=KCCKD2_HXDJ, KCCKD2_HXJE=KCCKD2_HXJE, KCCKD2_GZZX=KCCKD2_GZZX, KCCKD2_PCH=KCCKD2_PCH,
KCCKD2_HWBH=KCCKD2_HWBH, KCCKD2_ZYX1=KCCKD2_ZYX1, KCCKD2_ZYX2=KCCKD2_ZYX2, KCCKD2_ZYX3=KCCKD2_ZYX3, KCCKD2_ZYX4=KCCKD2_ZYX4, KCCKD2_ZYX5=KCCKD2_ZYX5, KCCKD2_WLZT=KCCKD2_WLZT, KCCKD2_WLBZ=KCCKD2_WLBZ, KCCKD2_QLSL=KCCKD2_QLSL, KCCKD2_SL=KCCKD2_SL, KCCKD2_DJ=KCCKD2_DJ, KCCKD2_JE=KCCKD2_JE, KCCKD2_FSL1=KCCKD2_FSL1, KCCKD2_FSL2=KCCKD2_FSL2, KCCKD2_TDFL=KCCKD2_TDFL, KCCKD2_XEFL=KCCKD2_XEFL, KCCKD2_BZBH=KCCKD2_BZBH, KCCKD2_GXBH=KCCKD2_GXBH, KCCKD2_ZJZT=KCCKD2_ZJZT, KCCKD2_ZJJL=KCCKD2_ZJJL,
KCCKD2_CLFS=KCCKD2_CLFS, KCCKD2_ZJWC=KCCKD2_ZJWC, KCCKD2_JSSL=KCCKD2_JSSL, KCCKD2_BGDH=KCCKD2_BGDH, KCCKD2_BZ=KCCKD2_BZ, KCCKD2_C1=KCCKD2_C1, KCCKD2_C2=KCCKD2_C2, KCCKD2_C3=KCCKD2_C3, KCCKD2_C4=KCCKD2_C4, KCCKD2_C5=KCCKD2_C5, KCCKD2_U1=KCCKD2_U1, KCCKD2_U2=KCCKD2_U2, KCCKD2_U3=KCCKD2_U3, KCCKD2_FSL3=KCCKD2_FSL3, KCCKD2_FQLSL=KCCKD2_FQLSL, KCCKD2_CXESL=KCCKD2_CXESL, KCCKD2_CBBZ=KCCKD2_CBBZ, KCCKD2_THDZSL=KCCKD2_THDZSL, KCCKD2_THDJCSL=KCCKD2_THDJCSL, KCCKD2_SCSQLS=KCCKD2_SCSQLS, KCCKD2_SCSQFL=KCCKD2_SCSQFL,
KCCKD2_SCDDLS=KCCKD2_SCDDLS

Using the following key columns for target table GGSCHEMA.KCCKD2: KCCKD2_PJLX, KCCKD2_LSBH, KCCKD2_FLBH, KCCKD2_WLBH, KCCKD2_TSKC, KCCKD2_XGDX, KCCKD2_DDLS, KCCKD2_DDFL, KCCKD2_TDLS, KCCKD2_WTLS, KCCKD2_WTFL, KCCKD2_QLLS, KCCKD2_QLFL, KCCKD2_HXSL, KCCKD2_HXFSL1, KCCKD2_HXFSL2, KCCKD2_HXDJ, KCCKD2_HXJE, KCCKD2_GZZX, KCCKD2_PCH, KCCKD2_HWBH, KCCKD2_ZYX1, KCCKD2_ZYX2, KCCKD2_ZYX3, KCCKD2_ZYX4, KCCKD2_ZYX5, KCCKD2_WLZT, KCCKD2_WLBZ, KCCKD2_QLSL, KCCKD2_SL, KCCKD2_DJ, KCCKD2_JE, KCCKD2_FSL1, KCCKD2_FSL2, KCCKD2_TDFL, KCCKD2_XEFL, KCCKD2_BZBH, KCCKD2_GXBH, KCCKD2_ZJZT, KCCKD2_ZJJL, KCCKD2_CLFS, KCCKD2_ZJWC, KCCKD2_JSSL, KCCKD2_BGDH, KCCKD2_BZ, KCCKD2_C1, KCCKD2_C2, KCCKD2_C3, KCCKD2_C4, KCCKD2_C5, KCCKD2_U1, KCCKD2_U2, KCCKD2_U3, KCCKD2_FSL3, KCCKD2_FQLSL, KCCKD2_CXESL, KCCKD2_CBBZ, KCCKD2_THDZSL, KCCKD2_THDJCSL, KCCKD2_SCSQLS, KCCKD2_SCSQFL, KCCKD2_SCDDLS, ETL_FL_NM, BUSI_DATE, PPN_TMSTAMP, OPERTYPE, MODIFY_DATATIME.


2011-05-25 18:22:17 WARNING OGG-01004 Aborted grouped transaction on 'GGSCHEMA.KCCKD2', Database error 100 ([IBM][CLI Driver][DB2/LINUXX8664] SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000

).

2011-05-25 18:22:17 WARNING OGG-01003 Repositioning to rba 9546 in seqno 8.

2011-05-25 18:22:17 WARNING OGG-01154 SQL error 100 mapping LC0019999.KCCKD2 to GGSCHEMA.KCCKD2 [SQL error 100 (0x64)][IBM][CLI Driver][DB2/LINUXX8664] SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000.

2011-05-25 18:22:17 WARNING OGG-01003 Repositioning to rba 9546 in seqno 8.

Source Context :
SourceModule : [er.main]
SourceID : [/mnt/ecloud/workspace/Build_OpenSys_r11.1.1.0.0_078_[37283]/perforce/src/app/er/rep.c]
SourceFunction : [take_rep_err_action]
SourceLine : [15780]
ThreadBacktrace : [8] elements
: [/db2/ggv11db2/replicat(CMessageContext::AddThreadContext()+0x26) [0x70a036]]
: [/db2/ggv11db2/replicat(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...)+0x7b2) [0x700ad2]]
: [/db2/ggv11db2/replicat(_MSG_ERR_MAP_TO_TANDEM_FAILED(CSourceContext*, DBString<777> const&, DBString<777> const&, CMessageFactory::MessageDisposition)+0x9b) [0x6ac89b]]
: [/db2/ggv11db2/replicat [0x550e93]]
: [/db2/ggv11db2/replicat [0x55a20a]]
: [/db2/ggv11db2/replicat(main+0xe9c) [0x55bedc]]
: [/lib64/libc.so.6(__libc_start_main+0xf4) [0x389281d974]]
: [/db2/ggv11db2/replicat(__gxx_personality_v0+0x19a) [0x4ce81a]]

2011-05-25 18:22:17 ERROR OGG-01296 Error mapping from LC0019999.KCCKD2 to GGSCHEMA.KCCKD2.[@more@]





如何解决Oracle GoldenGate 没有主键的问题?

针对没有主键的情况,GoldenGate大概提供了3种方案,大致如下:

1、默认使用所有列当主键,通过keycols来实现,这种其实存在一定的问题,在这次的项目中直接否定。

2、通过在源端表中添加ogg_key_id列的方式来实现,这可能会影响应用,因此也直接否定。

3、通过在目标端的表中添加rowid类型的伪列,来实现。通过测试,发现这种相对靠谱,如下是我的测试过程.

我这里测试的ogg抽取9208 Dataguard standby,同步到10205的例子。另外,我们这里9i的环境和10g环境均在同一个主机.

1、源端

说明:这里我模拟的是9i环境超过32列的情况.

—创建测试表

SQL> conn roger/roger
Connected.
SQL> create table t_ALL_TABLES as select * from sys.ALL_TABLES where 1=2; Table created.

—源端OGG配置

GGSCI (killdb.com) 2> view param ext_std

extract ext_std
 userid ggs@killdb,password ggs
 tranlogoptions archivedlogonly
 tranlogoptions altarchivelogdest /home/ora9/arch_s
 exttrail /home/ora9/ggs/dirdat/ra
 discardfile ./dirrpt/exta.dsc,append, megabytes 500 fetchoptions USEROWID table roger.t_all_tables, tokens (TKN-ROWID = @GETENV ("RECORD", "rowid")) keycols (owner) ;
 table roger.t_buffer; GGSCI (killdb.com) 3> view param dp1 EXTRACT dp1 RMTHOST 192.168.109.12, MGRPORT 7809 TCPBUFSIZE 5000000 PASSTHRU RMTTRAIL ./dirdat/r1 NUMFILES 3000 TABLE roger.*; GGSCI (killdb.com) 5> dblogin userid ggs@killdb,password ggs Successfully logged into database. GGSCI (killdb.com) 6> add trandata roger.t_all_Tables cols(owner) nokey 2014-12-17 01:49:59 WARNING OGG-00869 No unique key is defined for table T_ALL_TABLES. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key. Logging of supplemental redo data enabled for table ROGER.T_ALL_TABLES.

2. 目标端

—创建测试表

www.killdb.com>create table t_all_tables as select * from sys.all_tables where 1=2; Table created.

www.killdb.com>alter table t_all_Tables drop column STATUS ; Table altered.

www.killdb.com>alter table t_all_Tables drop column DROPPED; Table altered.

www.killdb.com>alter table t_all_tables add (row_id rowid); Table altered.

www.killdb.com> alter table roger.t_all_Tables add constraint t_all_tables_pk unique (row_id) enable; Table altered.

—目标端OGG配置

GGSCI (killdb.com) 2> view param rep6

replicat rep6
userid  ggs@Roger,password AADAAAAAAAAAAADAKHEJYIFGVAKDPFZBGDFJNEQBBJRISJAAOCHHZEWCEFTCRIRCJDSHUHAJZBFDZEWC,encryptkey kasaur_key
reperror default, discard
discardfile ./dirrpt/rep6.dsc, append, megabytes 50 handlecollisions
assumetargetdefs
----allownoopupdates
numfiles 3000 map roger.t_buffer, target roger.t_buffer; map roger.t_all_tables , target roger.t_all_tables colmap (usedefaults, row_id = @token ("TKN-ROWID")) keycols (row_id);

3. 启动进程

–源端

GGSCI (killdb.com) 5> info all Program Status Group Lag Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING DP1 00:00:00 00:00:07 EXTRACT RUNNING EXT_STD 00:00:00 00:00:07

—目标端

GGSCI (killdb.com) 3> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING JAGENT STOPPED EXTRACT ABENDED DP1 00:00:00 568:19:49 EXTRACT ABENDED EXT1 00:00:00 309:16:06 REPLICAT STOPPED REP5 00:00:00 596:25:54 REPLICAT RUNNING REP6 00:00:00 00:00:02

4. 源端插入测试数据

模拟insert:

–源端

SQL> insert into t_all_Tables select * from sys.all_Tables where rownum < 11; 10 rows created.

SQL> commit; Commit complete. SQL> alter system switch logfile; System altered.

SQL>

—-目标端

www.killdb.com>select count(1) from t_all_Tables; COUNT(1)
---------- 10 www.killdb.com>select owner,table_name,row_id from t_all_Tables; OWNER TABLE_NAME ROW_ID ------------------------------ ------------------------------ ------------------ SYS SEG$  AAAH3QAABAAAV0yAAA SYS CLU$  AAAH3QAABAAAV0yAAB SYS OBJ$  AAAH3QAABAAAV0yAAC SYS FILE$  AAAH3QAABAAAV0yAAD SYS COL$  AAAH3QAABAAAV0yAAE SYS CON$  AAAH3QAABAAAV0yAAF SYS PROXY_DATA$  AAAH3QAABAAAV0yAAG SYS USER$  AAAH3QAABAAAV0yAAH SYS IND$  AAAH3QAABAAAV0yAAI SYS FET$  AAAH3QAABAAAV0yAAJ 10 rows selected.

模式delete:

–源端

SQL> delete from t_all_tables where rownum < 5; 4 rows deleted.

SQL> commit; Commit complete. SQL> alter system switch logfile; System altered.

SQL> select count(1) from t_all_tables; COUNT(1) ---------- 6

SQL> select owner,table_name,rowid from t_all_tables; OWNER                          TABLE_NAME                     ROWID ------------------------------ ------------------------------ ------------------ SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

—目标端:

www.killdb.com>select count(1) from t_all_Tables; COUNT(1) ---------- 6

www.killdb.com>select owner,table_name,row_id from t_all_Tables; OWNER                          TABLE_NAME                     ROW_ID ------------------------------ ------------------------------ ------------------ SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

www.killdb.com>

模拟update:

—源端:

SQL> select owner,table_name,rowid from t_all_tables; OWNER                          TABLE_NAME                     ROWID ------------------------------ ------------------------------ ------------------ SYS                            COL$                           AAAH3QAABAAAV0yAAE
SYS                            CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

SQL> update t_all_tables set owner='killdb.com' where table_name='COL$'; 1 row updated.

SQL> update t_all_tables set owner='killdb.com' where rowid='AAAH3QAABAAAV0yAAF'; 1 row updated.

SQL> commit; Commit complete. SQL> alter system switch logfile; System altered.

SQL> select owner,table_name,rowid from t_all_tables; OWNER                          TABLE_NAME                     ROWID ------------------------------ ------------------------------ ------------------ killdb.com                     COL$                           AAAH3QAABAAAV0yAAE
killdb.com                     CON$                           AAAH3QAABAAAV0yAAF
SYS                            PROXY_DATA$                    AAAH3QAABAAAV0yAAG
SYS                            USER$                          AAAH3QAABAAAV0yAAH
SYS                            IND$                           AAAH3QAABAAAV0yAAI
SYS                            FET$                           AAAH3QAABAAAV0yAAJ

6 rows selected.

–目标端:

www.killdb.com> select owner,table_name,row_id from t_all_Tables; OWNER TABLE_NAME ROW_ID ------------------------------ ------------------------------ ------------------
killdb.com COL$  AAAH3QAABAAAV0yAAE killdb.com CON$  AAAH3QAABAAAV0yAAF SYS PROXY_DATA$  AAAH3QAABAAAV0yAAG SYS USER$  AAAH3QAABAAAV0yAAH SYS IND$  AAAH3QAABAAAV0yAAI SYS FET$  AAAH3QAABAAAV0yAAJ 6 rows selected.

www.killdb.com>

我们可以看到ogg完全是可以支持利用构造rowid伪列的方式来解决没有主键的问题。 然而这种方法也有一个很大的问题:迁移之后,新环境中的row_id 伪列需要进行drop,这个drop的动作是非常坑爹的。

例如我们客户这里的系统,均为2.5TB以上的,最大12TB的库,那么drop column就疯掉了。






goldengate 同步无主键表

scott.bonus表无主键无唯一索引,若是在gg源端发出,会导致gg目的端abend,除非目的端复制进程参数文件有APPLYNOOPUPDATES 或者ALLOWNOOPUPDATES  参数)

update scott.t1 set ename='bos' where ename='bos2';


gg目的端abend时,dirrpt下的rpt文件报错如下:


2011-09-14 09:35:23  ERROR   OGG-01168  Encountered an update for target table SCOTT2.BONUS, which has no unique key defined.  KEYCOLS can be used to define a key.
Use ALLOWNOOPUPDATES to process the update without applying it to the target database. 
Use APPLYNOOPUPDATES to force the update to be applied using all columns in both the SET and WHERE clause

 

所以在目标端的配置文件中加入参数 APPLYNOOPUPDATES 或者ALLOWNOOPUPDATES  参数




GOLDENGATE–无主键表的解决方案

问题:有些表格没有主键或者唯一性索引,并且无法确定其关键列,而现实也不允许将所有的列当做关键列!在这种情况下如何使用GG来完成表格的同步?
解决:在备份端得表格添加一个列,并将生产库的rowid的map到该列。

        
1、使用这种办法的前提是在初次同步时就要将生产端得rowid同步过来。
可以使用如下方法实现:
备份端:

create table xue.test6 (id number,name varchar2(20),name1 varchar2(20),row_id rowid);

insert into xue.test6 select t.*,rowid from xue.test6@mynewdb t;

面对比较大的表,需要分批插入,也要考虑使用parallel

在备份端row_id上创建唯一性约束:
alter table xue.test6 add constraint test6_uni unique (row_id) enable;

2、配置:
extxue:
extract extxue
userid ggs@mynewdb, password ggs
exttrail ./dirdat/xx
tranlogoptions ARCHIVEDLOGONLY
tranlogoptions altarchivelogdest /Tbackup/mcstar/mynewdbarch
fetchoptions USEROWID
table xue.test6, tokens (TKN-ROWID = @GETENV ("RECORD", "rowid")) keycols (id) ;
—注意,keycols(id)是必须的,id可以是其他的实际列,但不能是虚拟列,例如rowid。

repxue:
replicat repxue
userid ggs@drb, password ggs
handlecollisions
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/roraxx.dsc, APPEND
map xue.test6 , target xue.test6 colmap (usedefaults, row_id = @token ("TKN-ROWID")) keycols (row_id);
—注意,KEYCOLS里只有row_id即可

3、
add trandata xue.test6 cols(id) nokey

–注意,此处的id与在2中配置的extxue的参数中的KEYCOLS(id)对应。

4、经过如上配置,可以实现以rowid为keycols进行复制:

生产端得表格:
SQL> select * from xue.test6;

        ID NAME                 NAME1
———- ——————– —————————————-
         1 iooooo               n
         1 m                    n
         1 m                    n
         2 m                    n
         3 m                    n
         3 c                    m
         2 f                    m
         2 f                    m
         3 m                    m
        
生产端做操作:
SQL> update xue.test6 set name1=’ss’ where rownum<3;

2 rows updated.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

备份端得应用语句:
UPDATE "XUE"."TEST6" SET "ID"=’1′,"NAME1"=’ss’ WHERE "ROW_ID"=’AAADtWAABAAAH86AAA’
Statement length: 82

(S)top display, (K)eep displaying (default): K

 

UPDATE "XUE"."TEST6" SET "ID"=’1′,"NAME1"=’ss’ WHERE "ROW_ID"=’AAADtWAABAAAH86AAB’
Statement length: 82

(S)top display, (K)eep displaying (default): K

备份端应用后的数据:
        ID NAME                                     NAME1      ROW_ID
———- —————————————- ———- ——————
         1 iooooo                                   ss         AAADtWAABAAAH86AAA
         1 m                                        ss         AAADtWAABAAAH86AAB
         1 m                                        n          AAADtWAABAAAH86AAC
         2 m                                        n          AAADtWAABAAAH86AAD
         3 m                                        n          AAADtWAABAAAH86AAE
         3 c                                        m          AAADtWAABAAAH86AAF
         2 f                                        m          AAADtWAABAAAH86AAG
         2 f                                        m          AAADtWAABAAAH86AAH
         3 m                                        m          AAADtWAABAAAH87AAA

—–注意,本文只是为了提供解决办法,实际的部署环境需要调整步骤的顺序,比如,在启动extxue之前,需要完成add trandata;在做初次同步之前需要保证extract进程已经在挖掘你要同步的表

<!-- Baidu Button BEGIN -->
<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24162410/viewspace-1813775/,如需转载,请注明出处,否则将追究法律责任。

下一篇: oracle RAC CVU介绍
请登录后发表评论 登录
全部评论

注册时间:2010-06-28

  • 博文量
    52
  • 访问量
    80499