Use data define file and colmap to map different column

通常我们使用OGG同步一个表的时候,遇见两个表的列不一样,这时候我们就需要使用数据定义文件和colmap将行进行映射

下面我们来看看源表的结构:

SQL> desc test3;
Name                                                  Null?    Type
----------------------------------------------------- -------- ------------------------------------
OWNER                                                 NOT NULL VARCHAR2(30)
TABLE_NAME                                            NOT NULL VARCHAR2(30)
TABLESPACE_NAME                                                VARCHAR2(30)
CLUSTER_NAME                                                   VARCHAR2(30)
IOT_NAME                                                       VARCHAR2(30)
STATUS                                                         VARCHAR2(8)
PCT_FREE                                                       NUMBER
PCT_USED                                                       NUMBER
INI_TRANS                                                      NUMBER
MAX_TRANS                                                      NUMBER
INITIAL_EXTENT                                                 NUMBER
NEXT_EXTENT                                                    NUMBER
MIN_EXTENTS                                                    NUMBER
MAX_EXTENTS                                                    NUMBER
PCT_INCREASE                                                   NUMBER
FREELISTS                                                      NUMBER
FREELIST_GROUPS                                                NUMBER
LOGGING                                                        VARCHAR2(3)
BACKED_UP                                                      VARCHAR2(1)
NUM_ROWS                                                       NUMBER
BLOCKS                                                         NUMBER
EMPTY_BLOCKS                                                   NUMBER
AVG_SPACE                                                      NUMBER
CHAIN_CNT                                                      NUMBER
AVG_ROW_LEN                                                    NUMBER
AVG_SPACE_FREELIST_BLOCKS                                      NUMBER
NUM_FREELIST_BLOCKS                                            NUMBER
DEGREE                                                         VARCHAR2(20)
INSTANCES                                                      VARCHAR2(20)
CACHE                                                          VARCHAR2(10)
TABLE_LOCK                                                     VARCHAR2(8)
SAMPLE_SIZE                                                    NUMBER
LAST_ANALYZED                                                  DATE
PARTITIONED                                                    VARCHAR2(3)
IOT_TYPE                                                       VARCHAR2(12)
TEMPORARY                                                      VARCHAR2(1)
SECONDARY                                                      VARCHAR2(1)
NESTED                                                         VARCHAR2(3)
BUFFER_POOL                                                    VARCHAR2(7)
FLASH_CACHE                                                    VARCHAR2(7)
CELL_FLASH_CACHE                                               VARCHAR2(7)
ROW_MOVEMENT                                                   VARCHAR2(8)
GLOBAL_STATS                                                   VARCHAR2(3)
USER_STATS                                                     VARCHAR2(3)
DURATION                                                       VARCHAR2(15)
SKIP_CORRUPT                                                   VARCHAR2(8)
MONITORING                                                     VARCHAR2(3)
CLUSTER_OWNER                                                  VARCHAR2(30)
DEPENDENCIES                                                   VARCHAR2(8)
COMPRESSION                                                    VARCHAR2(8)
COMPRESS_FOR                                                   VARCHAR2(12)
DROPPED                                                        VARCHAR2(3)
READ_ONLY                                                      VARCHAR2(3)
SEGMENT_CREATED                                                VARCHAR2(3)
RESULT_CACHE                                                   VARCHAR2(7)


SQL> select count(1) from test3;

  COUNT(1)
----------
      2822

目标表的结构:

SQL> desc test3;
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
OWNER                                     NOT NULL VARCHAR2(30)
TABLE_NAME                                NOT NULL VARCHAR2(30)
TABLESPACE_NAME                                    VARCHAR2(30)

SQL>
SQL>
SQL>
SQL> select count(1) from test3;

  COUNT(1)
----------
         0

SQL>

具体操作如下:
前期安装配置就不详细介绍了,请参考前面的文章 。
这里先使用ogg的initload 方法同步源表已有的数据:
Source:

add extract initload,sourceistable;

edit param initload

extract initload
userid ogg, password ogg
rmthost 192.168.56.61,mgrport 7839
rmttask replicat, group repload
table zbdba.test3;

创建数据定义文件:

GGSCI (zbdba1) 7> edit param defgen

defsfile ./dirsql/convert.sql
userid ogg,password ogg
table zbdba.test3;

[ogg@zbdba1 ogg]$ ./defgen paramfile /ogg/dirprm/defgen.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 2015-03-02 15:59:20

***********************************************************************

Operating System Version:
Linux
Version #1 SMP Wed Jun 13 18:24:36 EDT 2012, Release 2.6.32-279.el6.x86_64
Node: zbdba1
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: 7481

***********************************************************************
**            Running with the following parameters                  **
***********************************************************************
defsfile ./dirsql/convert.sql
userid ogg,password ***
table zbdba.test3;
Retrieving definition for ZBDBA.TEST3

2015-03-02 15:59:24  WARNING OGG-00869  No unique key is defined for table 'TEST3'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.



Definitions generated for 1 table in ./dirsql/convert.sql


[ogg@zbdba1 dirsql]$ cat convert.sql
*+- Defgen version 2.0, Encoding UTF-8
*
* Definitions created/modified  2015-03-02 15:59
*
*  Field descriptions for each column entry:
*
*     1    Name
*     2    Data Type
*     3    External Length
*     4    Fetch Offset
*     5    Scale
*     6    Level
*     7    Null
*     8    Bump if Odd
*     9    Internal Length
*    10    Binary Length
*    11    Table Length
*    12    Most Significant DT
*    13    Least Significant DT
*    14    High Precision
*    15    Low Precision
*    16    Elementary Item
*    17    Occurs
*    18    Key Column
*    19    Sub Data Type
*
Database type: ORACLE
Character set ID: windows-936
National character set ID: UTF-16
Locale: neutral
Case sensitivity: 14 14 14 14 14 14 14 14 14 14 14 14 11 14 14 14
*
Definition for table ZBDBA.TEST3
Record length: 1704
Syskey: 0
Columns: 55
OWNER                       64     30        0  0  0 1 0     30     30      0 0 0 0 0 1    0 1 0
TABLE_NAME                  64     30       36  0  0 1 0     30     30      0 0 0 0 0 1    0 1 0
TABLESPACE_NAME             64     30       72  0  0 1 0     30     30      0 0 0 0 0 1    0 1 0
CLUSTER_NAME                64     30      108  0  0 1 0     30     30      0 0 0 0 0 1    0 1 0
IOT_NAME                    64     30      144  0  0 1 0     30     30      0 0 0 0 0 1    0 1 0
STATUS                      64      8      180  0  0 1 0      8      8      0 0 0 0 0 1    0 1 0
PCT_FREE                    64     50      194  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
PCT_USED                    64     50      250  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
INI_TRANS                   64     50      306  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
MAX_TRANS                   64     50      362  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
INITIAL_EXTENT              64     50      418  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
NEXT_EXTENT                 64     50      474  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
MIN_EXTENTS                 64     50      530  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
MAX_EXTENTS                 64     50      586  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
PCT_INCREASE                64     50      642  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
FREELISTS                   64     50      698  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
FREELIST_GROUPS             64     50      754  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
LOGGING                     64      3      810  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
BACKED_UP                   64      1      818  0  0 1 0      1      1      0 0 0 0 0 1    0 1 0
NUM_ROWS                    64     50      824  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
BLOCKS                      64     50      880  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
EMPTY_BLOCKS                64     50      936  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
AVG_SPACE                   64     50      992  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
CHAIN_CNT                   64     50     1048  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
AVG_ROW_LEN                 64     50     1104  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
AVG_SPACE_FREELIST_BLOCKS   64     50     1160  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
NUM_FREELIST_BLOCKS         64     50     1216  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
DEGREE                      64     20     1272  0  0 1 0     20     20      0 0 0 0 0 1    0 1 0
INSTANCES                   64     20     1298  0  0 1 0     20     20      0 0 0 0 0 1    0 1 0
CACHE                       64     10     1324  0  0 1 0     10     10      0 0 0 0 0 1    0 1 0
TABLE_LOCK                  64      8     1340  0  0 1 0      8      8      0 0 0 0 0 1    0 1 0
SAMPLE_SIZE                 64     50     1354  0  0 1 0     50     50     50 0 0 0 0 1    0 1 2
LAST_ANALYZED              192     19     1410  0  0 1 0     19     19     19 0 5 0 0 1    0 1 0
PARTITIONED                 64      3     1432  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
IOT_TYPE                    64     12     1440  0  0 1 0     12     12      0 0 0 0 0 1    0 1 0
TEMPORARY                   64      1     1458  0  0 1 0      1      1      0 0 0 0 0 1    0 1 0
SECONDARY                   64      1     1464  0  0 1 0      1      1      0 0 0 0 0 1    0 1 0
NESTED                      64      3     1470  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
BUFFER_POOL                 64      7     1478  0  0 1 0      7      7      0 0 0 0 0 1    0 1 0
FLASH_CACHE                 64      7     1490  0  0 1 0      7      7      0 0 0 0 0 1    0 1 0
CELL_FLASH_CACHE            64      7     1502  0  0 1 0      7      7      0 0 0 0 0 1    0 1 0
ROW_MOVEMENT                64      8     1514  0  0 1 0      8      8      0 0 0 0 0 1    0 1 0
GLOBAL_STATS                64      3     1528  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
USER_STATS                  64      3     1536  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
DURATION                    64     15     1544  0  0 1 0     15     15      0 0 0 0 0 1    0 1 0
SKIP_CORRUPT                64      8     1564  0  0 1 0      8      8      0 0 0 0 0 1    0 1 0
MONITORING                  64      3     1578  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
CLUSTER_OWNER               64     30     1586  0  0 1 0     30     30      0 0 0 0 0 1    0 1 0
DEPENDENCIES                64      8     1622  0  0 1 0      8      8      0 0 0 0 0 1    0 1 0
COMPRESSION                 64      8     1636  0  0 1 0      8      8      0 0 0 0 0 1    0 1 0
COMPRESS_FOR                64     12     1650  0  0 1 0     12     12      0 0 0 0 0 1    0 1 0
DROPPED                     64      3     1668  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
READ_ONLY                   64      3     1676  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
SEGMENT_CREATED             64      3     1684  0  0 1 0      3      3      0 0 0 0 0 1    0 1 0
RESULT_CACHE                64      7     1692  0  0 1 0      7      7      0 0 0 0 0 1    0 1 0
End of definition

Target:

GGSCI (zbdba2) 6> add replicat repload,specialrun;
REPLICAT added.


GGSCI (zbdba2) 7>

GGSCI (zbdba2) 7>

GGSCI (zbdba2) 7> edit param repload

REPLICAT repload
USERID ogg, PASSWORD ogg
SOURCEDEFS ./dirsql/convert.sql
MAP zbdba.test3, TARGET zbdba.test3,
colmap (
owner=owner, table_name=table_name,tablespace_name=tablespace_name)
;
开启抽取进程:

GGSCI (zbdba1) 6> start initload


Sending START request to MANAGER ...
EXTRACT INITLOAD starting

查看日志:

2015-03-02 16:11:12  INFO    OGG-00993  Oracle GoldenGate Capture for Oracle, initload.prm:  EXTRACT INITLOAD started.
2015-03-02 16:11:42  INFO    OGG-00991  Oracle GoldenGate Capture for Oracle, initload.prm:  EXTRACT INITLOAD stopped normally.

Target:
2015-03-03 02:44:33  INFO    OGG-00973  Oracle GoldenGate Manager for Oracle, mgr.prm:  Manager started replicat task process (Port 7840).
2015-03-03 02:44:48  INFO    OGG-01229  Oracle GoldenGate Delivery for Oracle:  Connected to :37943.
2015-03-03 02:44:48  INFO    OGG-00995  Oracle GoldenGate Delivery for Oracle, repload.prm:  REPLICAT REPLOAD starting.
2015-03-03 02:44:48  INFO    OGG-03035  Oracle GoldenGate Delivery for Oracle, repload.prm:  Operating system character set identified as UTF-8. Locale: en_US, LC_ALL:.
2015-03-03 02:44:48  INFO    OGG-01815  Oracle GoldenGate Delivery for Oracle, repload.prm:  Virtual Memory Facilities for: COM
    anon alloc: mmap(MAP_ANON)  anon free: munmap
    file alloc: mmap(MAP_SHARED)  file free: munmap
    target directories:
    /ogg/dirtmp.
2015-03-03 02:44:48  INFO    OGG-00996  Oracle GoldenGate Delivery for Oracle, repload.prm:  REPLICAT REPLOAD started.
2015-03-03 02:44:52  WARNING OGG-00869  Oracle GoldenGate Delivery for Oracle, repload.prm:  No unique key is defined for table 'TEST3'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.
2015-03-03 02:44:57  INFO    OGG-00994  Oracle GoldenGate Delivery for Oracle, repload.prm:  REPLICAT REPLOAD stopped normally.


已经同步完成:
查看目标库数据:
SQL> select count(1) from test3;

  COUNT(1)
----------
      2822

SQL>

自此已完成初始化





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值