一、源端(Oracle)配置
1.创建同步测试表
create table gg_user.t01(name varchar(20) primary key);
create table gg_user.t02(id int primary key,name varchar(20));
2.添加定义文件(是异构之间的传输,需要转换字段类型等处理需用到defgen工具生成定义文件)
GGSCI (kermart) 4> edit params defgen
defsfile D:ggatedirdeft01.def
userid gg_user,password oracle
table gg_user.t01;
table gg_user.t02;
注意:如果有多个表,需要每个都列出来,如果这个用户所有的表都需要同步,直接就table gg_user.*;
如果没有列出来,复制进程启动会报如下错误:
ERROR OGG-00423 Oracle GoldenGate Delivery for SQL Server, RPL01.prm: Could not find definition for GG_USER.T02.
ERROR OGG-01668 Oracle GoldenGate Delivery for SQL Server, RPL01.prm: PROCESS ABENDING.
生成定义文件
D:ggate>defgen.exe paramfile D:ggatedirprmdefgen.prm
***********************************************************************
Oracle GoldenGate Table Definition Generator for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
Windows x64 (optimized), Oracle 11g on Apr 23 2012 05:48:41
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
Starting at 2014-04-24 16:43:37
***********************************************************************
Operating System Version:
Microsoft Windows 7 , on x64
Version 6.1 (Build 7601: Service Pack 1)
Process id: 6828
***********************************************************************
** Running with the following parameters **
***********************************************************************
defsfile D:ggatedirdeft01.def
userid gg_user,password ******
table gg_user.t;
Retrieving definition for GG_USER.T
Definitions generated for 1 table in D:ggatedirdeft01.def
将t01.def拷贝到sql server ogg下的dirdef目录下。
3.添加补充日志
GGSCI (kermart) 7> dblogin userid gg_user,password oracle
GGSCI (kermart) 8> add trandata gg_user.t01
GGSCI (kermart) 8> add trandata gg_user.t02
4.添加抽取进程
GGSCI (kermart) 5> edit params ext01
extract ext01
userid gg_user,password oracle
exttrail D:ggatedirdatet
DYNAMICRESOLUTION
GETTRUNCATES
TABLE gg_user.t01;
TABLE gg_user.t02;
GGSCI (kermart) 1> add extract ext01,tranlog,begin now
GGSCI (kermart) 2> add exttrail D:ggatedirdatet,extract ext01
5.添加传递进程
GGSCI (kermart) 6> edit params pump01
extract pump01
userid gg_user,password oracle
rmthost 127.0.0.1,mgrport 7810
rmttrail E:ggatedirdatrt
PASSTHRU
TABLE gg_user.t01;
TABLE gg_user.t02;
GGSCI (kermart) 5> add extract pump01,exttrailsource D:ggatedirdatet,begin now
GGSCI (kermart) 6> add rmttrail E:ggatedirdatrt,extract pump01
二、目标端(sql server)配置
1.配置ODBC数据源
控制面板-管理工具-数据源(ODBC),添加系统DNS,取名为test01,注意择驱动程序类型为SQL Server Native Client 10.0
2.创建测试表(结构跟源端保持一致)
create table hjj.t01(name varchar(20) primary key);
create table hjj.t02(id int primary key,name varchar(20));
3.添加checkpointtable
GGSCI (kermart) 10> edit param ./globals
checkpointtable hjj.ckp
GGSCI (kermart) 8> dblogin sourcedb t01 userid sa password sa
GGSCI (kermart) 9> add checkpointtable hjj.ckp
3.添加复制进程
GGSCI (kermart) 58> edit param rpl01
replicat rpl01
sourcedefs E:ggatedirdeft01.def
targetdb t01 userid sa, password sa
reperror default,discard
discardfile E:ggatedirrptrpl.dsc append
gettruncates
MAP gg_user.t01, TARGET hjj.t01;
MAP gg_user.t02, TARGET hjj.t02;
GGSCI (kermart) 12> add replicat rpl01,exttrail E:ggatedirdatrt,begin now,checkpointtable hjj.ckp
三、测试
1.启动进程
源端:
start ext01
start pump01
GGSCI (kermart) 9> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED EXDP 00:00:00 16:40:29
EXTRACT STOPPED EXORA 00:00:00 16:40:32
EXTRACT RUNNING EXT01 00:00:00 00:00:09
EXTRACT STOPPED EXT1 00:00:00 162:50:03
EXTRACT RUNNING PUMP01 00:00:00 00:00:05
EXTRACT STOPPED PUMP1 00:00:00 162:49:59
REPLICAT STOPPED MSREP 00:00:00 187:22:15
REPLICAT STOPPED REP1 00:00:00 163:47:29
目标端:
start rpl01
GGSCI (kermart) 59> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED EXT1 00:00:00 163:48:28
EXTRACT STOPPED MSEXT 00:00:00 187:23:13
EXTRACT STOPPED PUMP1 00:00:00 163:48:25
REPLICAT ABENDED ORAREP 00:00:00 16:57:48
REPLICAT STOPPED REP1 00:00:00 162:49:46
REPLICAT RUNNING RPL01 00:00:00 00:00:04
2.在源端(oracle)进行DML操作
SQL> insert into t01 select 'lyn'||rownum from dual connect by level commit;
提交完成。
SQL> insert into t02 select rownum,'moon'||rownum from dual connect by level commit;
提交完成。
SQL> select count(*) from t01;
COUNT(*)
----------
100
SQL> select count(*) from t02;
COUNT(*)
----------
100
3.在目标端(sql server)查看数据同步复制情况
C:>sqlcmd -S kermart -U sa -P sa -d TEST
1> select count(*) from hjj.t01;
2> go
-----------
100
(1 行受影响)
1> select count(*) from hjj.t02
2> go
-----------
100
(1 行受影响)
: