goldengate默认只是按照创建表时,列的顺序来执行数据的复制过程。
所以当两端的表有不同的name、length、type、顺序的时候,goldengate不会识别,会发生错误的现象。
这个时候就需要使用definition file来正确的进行表的映射。
使用definition file只要分三步:
1、生成一个param文件,用于指定需要生成definition的表以及生成的definition file的路径。
2、使用defgen根据param文件来生成definition文件。
3、修改replicat进程的参数文件,加入SourceDefs参数。
实验步骤如下:
1、创建测试表
首先创建测试表,22节点:
create table ggtb22 (id number primary key , name varchar2(20),sal number) ;
SQL> create table ggtb22 (id number primary key , name varchar2(20),sal number) ;
Table created.
23节点:
create table ggtb23 (id number primary key , name varchar2(20),salyear number) ;
SQL> create table ggtb23 (id number primary key , name varchar2(20),salyear number) ;
Table created.
2、添加trandata表级附加日志
GGSCI (oel51) 11> dblogin userid ggs password ggs
Successfully logged into database.
GGSCI (oel51) 12> add trandata dexter.ggtb22
Logging of supplemental redo data enabled for table DEXTER.GGTB22.
GGSCI (oel52) 19> dblogin userid ggs password ggs
Successfully logged into database.
GGSCI (oel52) 20> add trandata ggtb23
ERROR: No viable tables matched specification.
3、自行编辑一个params文件,放在dirprm目录中
[oracle@oel51 ogg]$ vi ./dirprm/defprmggtb22.prm
defsfile ./dirdef/ggtb22.def
USERID ggs, PASSWORD ggs
TABLE dexter.ggtb22;
4、然后使用defgen工具将definition file生成(defgen工具在ogg安装目录下)
使用命令后就会在dirdef目录中生成ggtb22.def文件
[oracle@oel51 ogg]$ ./defgen paramfile ./dirprm/defprmggtb22.prm
***********************************************************************
Oracle GoldenGate Table Definition Generator for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 05:08:19
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
Starting at 2016-03-12 02:00:02
***********************************************************************
Operating System Version:
Linux
Version #1 SMP Wed Feb 22 17:37:40 EST 2012, Release 2.6.32-300.10.1.el5uek
Node: oel51
Machine: x86_64
soft limit hard limit
Address Space Size : unlimited unlimited
Heap Size : unlimited unlimited
File Size : unlimited unlimited
CPU Time : unlimited unlimited
Process id: 13324
***********************************************************************
** Running with the following parameters **
***********************************************************************
defsfile ./dirdef/ggtb22.def
USERID ggs, PASSWORD ***
TABLE dexter.ggtb22;
Retrieving definition for DEXTER.GGTB22
Definitions generated for 1 table in ./dirdef/ggtb22.def
5、然后将该文件传送到目标端,我放在了dirdef目录中。
[oracle@oel51 ogg]$ scp ./dirdef/ggtb22.def 192.168.100.23:/u01/ogg/dirdef/
[email protected]'s password:
ggtb22.def 100% 1069 1.0KB/s 00:00
6、修改replicat文件加入如下内容
SourceDefs dirdef/ggtb22.def
然后开启相关进程即可开始同步。
双向复制时把上述步骤再次做一次,这里不再详述。
以下是各个进程参数文件(内容顺序皆为22节点,23节点),以及测试:
extract
extract eora
setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
userid ggs, password ggs
tranlogoptions dblogreader
tranlogoptions excludeuser ggs
threadoptions maxcommitpropagationdelay 20000
exttrail ./dirdat/bb
dynamicresolution
TABLE dexter.ggtb22 ;
extract eora
userid ggs, password ggs
tranlogoptions dblogreader
tranlogoptions excludeuser ggs
threadoptions maxcommitpropagationdelay 20000
exttrail ./dirdat/aa
dynamicresolution
TABLE dexter.ggtb23 ;
pump
extract pora23
dynamicresolution
userid ggs, password ggs
rmthost 192.168.100.23, mgrport 7139,compress
rmttrail ./dirdat/bb
TABLE dexter.ggtb22 ;
extract pora22
dynamicresolution
userid ggs, password ggs
rmthost 192.168.100.22, mgrport 7139,compress
rmttrail ./dirdat/aa
TABLE dexter.ggtb23 ;
replicat
replicat rora23
setenv (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
userid ggs, password ggs
--assumetargetdefs
SourceDefs ./dirdef/ggtb23.def
handlecollisions
reperror default,discard
DISCARDFILE ./dirrpt/rora23.dsc, append, megabytes 100
dynamicresolution
INSERTMISSINGUPDATES
MAP dexter.ggtb23, TARGET dexter.ggtb22,
COLMAP (USEDEFAULTS,
SAL = @COMPUTE(SALYEAR / 12)
NAME = @STRCAT(NAME,"HELLO"));
replicat rora22
setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
userid ggs, password ggs
--assumetargetdefs
SourceDefs ./dirdef/ggtb22.def
handlecollisions
reperror default,discard
DISCARDFILE ./dirrpt/rora22.dsc, append, megabytes 100
dynamicresolution
INSERTMISSINGUPDATES
MAP dexter.ggtb22, TARGET dexter.ggtb23,
COLMAP (USEDEFAULTS,
SALYEAR = @COMPUTE(SAL * 12)
NAME = @STRCAT(NAME,"hello"));
SQL> insert into ggtb22 values (1,'dex',10000) ;
1 row created.
SQL> commit ;
Commit complete.
SQL> select * from ggtb22 ;
ID NAME SAL
---------- -------------------- ----------
1 dex 10000
SQL> select * from ggtb23 ;
ID NAME SALYEAR
---------- -------------------- ----------
1 dexhello 120000
SQL> insert into ggtb23 values (2 , 'ter' , 10000) ;
1 row created.
SQL> commit ;
Commit complete.
SQL> select * from ggtb23 ;
ID NAME SALYEAR
---------- -------------------- ----------
1 dexhello 120000
2 ter 10000
SQL> select * from ggtb22 ;
ID NAME SAL
---------- -------------------- ----------
2 terHELLO 833.333333
1 dex 10000