OGG版本:19.1
RDBMS:19.15
测试目的:
源端表:bb.t2
目标端表: zbb.t4,zbb.t5 . t4和t5结构不同。t5中相对t4中多余的列为token获取的环境变量
同时将bb.t2同步到zbb.t4和zbb.t5 .
关于token和@getenv函数,可以参考官方文档 Oracle® GoldenGate Windows and UNIX Reference Guide
源端表:
BB@orcl>desc t2Name Null? Type----------------------------------------- -------- ----------------------------ID NUMBERNAME VARCHAR2(10)BB@orcl>
目标端表
conn zbb/oracle
create table t5 (
no number,
firstname varchar2(10), ## token名 = token值
host varchar2(40), -- TKN-HOST = @GETENV ('GGENVIRONMENT", "HOSTNAME'),
gg_group varchar2(40), -- TKN-GRP = @GETENV ('GGENVIRONMENT", "GROUPNAME'),
osuser varchar2(40), -- TKN-USER = @GETENV ('GGENVIRONMENT", "OSUSERNAME'),
domain varchar2(40), -- TKN-DOMAIN = @GETENV ('GGENVIRONMENT", "DOMAINNAME'),
UPDATETIME date, -- updatetime= @TOKEN ('GGHEADER','COMMITTIMESTAMP'),
tablename varchar2(40), -- TKN-TBNAME = @GETENV ('GGHEADER”, “TABLENAME'),
optype varchar2(40) -- TKN-OPT = @GETENV ('GGHEADER”, “OPTYPE'),
)
源端的ext2 ,源端ext进程,获取的环境变量较多,虽然针对t4表,用不了这么多,但是针对t5表,可以用到这些。不影响t2和t4,t2和t5的同时同步
table bb.t2 ,TOKENS & ## 一行写不下,可以使用符号&换行
(TKN-HOST = @GETENV ('GGENVIRONMENT', 'HOSTNAME'), &
TKN-GRP = @GETENV ('GGENVIRONMENT', 'GROUPNAME'), &
TKN-USER = @GETENV ('GGENVIRONMENT', 'OSUSERNAME'),&
TKN-DOMAIN = @GETENV ('GGENVIRONMENT', 'DOMAINNAME'),&
updatetime= @GETENV ('GGHEADER','COMMITTIMESTAMP'),&
TKN-TBNAME = @GETENV ('GGHEADER', 'TABLENAME'),&
TKN-OPT = @GETENV ('GGHEADER', 'OPTYPE'));
源端的pump2进程
table bb.t2 ,TOKENS &
(TKN-HOST = @GETENV ('GGENVIRONMENT', 'HOSTNAME'), &
TKN-GRP = @GETENV ('GGENVIRONMENT', 'GROUPNAME'), &
TKN-USER = @GETENV ('GGENVIRONMENT', 'OSUSERNAME'),&
TKN-DOMAIN = @GETENV ('GGENVIRONMENT', 'DOMAINNAME'),&
updatetime= @GETENV ('GGHEADER','COMMITTIMESTAMP'),&
TKN-TBNAME = @GETENV ('GGHEADER', 'TABLENAME'),&
TKN-OPT = @GETENV ('GGHEADER', 'OPTYPE'));
因为源端的表没有变化,所以不要再次生成defgen file,只需要在目标端rep2中添加map ,原来的对t4表的map,也存在
map bb.t2,target zbb.t4, COLMAP (USEDEFAULTS,no=id,firstname=name ,updatetime= @TOKEN ('updatetime')),filter (id > 30); -- 仅仅复制id>30map bb.t2,target zbb.t5, COLMAP ( &
USEDEFAULTS, &
no=id, &
firstname=name , &
host = @token ('TKN-HOST'), &
gg_group = @token ('TKN-GRP'), &
osuser= @token ('TKN-USER'), &
domain = @token('TKN-DOMAIN'),&
updatetime= @TOKEN ('updatetime'), &
tablename= @TOKEN ('TKN-TBNAME'), &
optype= @TOKEN ('TKN-OPT'), &
);
同步成功,原来的T4,也可以同步。 T2同时同步到T4,T5 .
ZBB@test>select * from t4;NO FIRSTNAME UPDATETIME
---------- ---------- -------------------------41 p 2022-07-13 16:56:2142 ae 2022-07-13 17:10:3743 iwc 2022-07-13 17:13:2247 mmm ## 这里没有结果,是因为map t2到t4的,token中,token名称写错了 ,修改后就可以了。48 ccc 2022-07-14 15:24:1514 c 2022-07-11 14:32:2815 d 2022-07-11 14:34:2311 c 2022-07-09 19:14:2313 c 2022-07-09 19:28:2918 a 2022-07-13 15:37:4319 m 2022-07-13 15:41:25NO FIRSTNAME UPDATETIME
---------- ---------- -------------------------32 c 2022-07-13 16:01:1440 i 2022-07-13 16:04:1341 m 2022-07-13 16:53:059 a 2022-07-08 14:33:0310 aa 2022-07-08 17:13:0717 a 2022-07-13 11:24:5416 a 2022-07-13 10:35:1218 rows selected.ZBB@test>select * from t5; ## DOmain字段没有结果,这个字段仅仅针对Windows,官方文档上有说明 NO FIRSTNAME HOST GG_GROUP OSUSER DOMAIN UPDATETIME TABLENAME OPTYPE
---------- ---------- ---------------- ---------- ---------- ---------- ------------------------- ---------- ----------44 aa redhat762100 PUMP2 oracle BB.T2 INSERT45 mw redhat762100 PUMP2 oracle BB.T2 INSERT46 afdsa redhat762100 PUMP2 oracle 2022-07-14 15:14:32 BB.T2 INSERT47 mmm redhat762100 PUMP2 oracle 2022-07-14 15:22:35 BB.T2 INSERT48 ccc redhat762100 PUMP2 oracle 2022-07-14 15:24:15 BB.T2 INSERTZBB@test>
END