使用@TOKEN函数 来获取存储在GOLDENGATE 用户同步记录头部数据字典的数据
可设置一些主机名、用户、进程名、操作等信息,对同步数据进行监控等有用
提取进程设置
extract sgs_sde
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
USERID goldengate, PASSWORD goldengate
RMTHOST 126.33.8.96, MGRPORT 8200
RMTTRAIL ./dirdat/gs
GETUPDATEBEFORES
TABLE sde.njP,
TOKENS ( TKN-GROUP-NAME =@GETENV ("GGENVIRONMENT", "GROUPNAME"),
TKN-HOST-NAME =@GETENV ("GGENVIRONMENT", "HOSTNAME"),
TKN-OS-USER =@GETENV ("GGENVIRONMENT", "OSUSERNAME"),
TKN-COMMIT-TS =@GETENV ("GGHEADER", "COMMITTIMESTAMP"),
TKN-LOG-POSITION =@GETENV ("GGHEADER", "LOGPOSITION"),
TKN-LOG-RBA =@GETENV ("GGHEADER", "LOGRBA"),
TKN-TABLE =@GETENV ("GGHEADER", "TABLENAME"),
TKN-OP-TYPE =@GETENV ("GGHEADER", "OPTYPE"),
TKN-REC-LEN =@GETENV ("GGHEADER", "RECORDLENGTH"),
TKN-TRNS-IND =@GETENV ("GGHEADER", "TRANSACTION INDICATOR"),
TKN-BA =@GETENV ("GGHEADER", "BEFOREAFTERINDICATOR"),
);
复制进程设置
replicat rep_sde
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
USERID goldengate@orcl, PASSWORD goldengate
ASSUMETARGETDEFS
INSERTALLRECORDS
MAP sde.njP, TARGET SGS_CHJ.chj_new_data_change_his,
COLMAP ( ID = ID,
SOURCE_HOST = @TOKEN ("TKN-HOST-NAME"),
SOURCE_USER = @TOKEN ("TKN-OS-USER"),
SOURCE_GROUP = @TOKEN ("TKN-GROUP-NAME"),
SOURCE_TABLE = @TOKEN ("TKN-TABLE"),
BEFORE_AFTER = @TOKEN ("TKN-BA"),
IO_TYPE = @TOKEN ("TKN-OP-TYPE"),
DEAL_DATE = @TOKEN ("TKN-COMMIT-TS"),
TARGET_HOST = @GETENV ("GGENVIRONMENT", "HOSTNAME"),
TARGET_USER = @GETENV ("GGENVIRONMENT", "OSUSERNAME"),
TARGET_GROUP = @GETENV ("GGENVIRONMENT", "GROUPNAME"),
COL10 = COL10
);
附目标ORACLE 表结构 (源表是空间数据)
-- Create table
create table CHJ_NEW_DATA_CHANGE_HIS
(
ID VARCHAR2(50),
SOURCE_HOST VARCHAR2(1000),
SOURCE_USER VARCHAR2(500),
SOURCE_GROUP VARCHAR2(500),
SOURCE_TABLE VARCHAR2(500),
BEFORE_AFTER VARCHAR2(32),
DEAL_DATE TIMESTAMP(6),
IO_TYPE VARCHAR2(32),
COL2 NVARCHAR2(1000),
COL3 NVARCHAR2(500),
COL4 NVARCHAR2(1000),
COL5 NVARCHAR2(1000),
COL6 NVARCHAR2(1000),
COL10 NUMBER,
TARGET_HOST NVARCHAR2(500),
TARGET_USER NVARCHAR2(1000),
TARGET_GROUP NVARCHAR2(1000),
COL7 NVARCHAR2(1000),
COL8 NVARCHAR2(1000),
COL9 NVARCHAR2(1000)
)
tablespace TBS_SGS_TEST
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
next 8
minextents 1
maxextents unlimited
);
-- Create/Recreate indexes
create unique index COL10_UNIQUE on CHJ_NEW_DATA_CHANGE_HIS (COL10)
tablespace TBS_SGS_TEST
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
//触发器 自动增长
create or replace trigger his_new_trigger
before insert on chj_new_data_change_his
for each row
begin
select chj_new_data_change_his_sqe.nextval into :new.COL10 from dual;
end;
//序列
-- Create sequence
create sequence CHJ_NEW_DATA_CHANGE_HIS_SQE
minvalue 1
maxvalue 999999999999999999999
start with 61
increment by 1
cache 20;