1. 程式人生 > >Goldengate 使用definition file完畢異構表同步

Goldengate 使用definition file完畢異構表同步

utf8 commit led via user file xtra rail ogre

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文件夾中
[[email protected] 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文件

[[email protected] 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文件夾中。


[[email protected] ogg]$ scp ./dirdef/ggtb22.def 192.168.100.23:/u01/ogg/dirdef/
[email protected] 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





Goldengate 使用definition file完畢異構表同步