环境:
SourceDB:
ip:192.168.6.20
hostname:ogg1
gg home c:\gg\
TargetDB:
ip:192.168.6.10
hostname:ogg2
gg home c:\gg\
1.SourceDB配置
1.1 修改归档及日志模式:
- SQL> select LOG_MODE,SUPPLEMENTAL_LOG_DATA_MIN,FORCE_LOGGING from v$database;
- LOG_MODE SUPPLEME FOR
- ------------ -------- ---
- NOARCHIVELOG NO NO
a)修改归档:
- shutdown immediate;
- startup mount;
- alter database archivelog;
- alter database open;
b)开启最小附加日志模式:
alter database add supplemental log data;
c)开启强制日志模式:
alter database force logging;
1.2 关闭recyblebin:
- SQL> show parameter recyclebin;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------
- recyclebin string on
- alter system set recyclebin=off scope=spfile;
- purge recyclebin
1.3 创建gg目录:
- C:\ggs>install addservice addevents
- C:\ggs>ggsci
- GGSCI (ogg1) 1> create subdirs
- Creating subdirectories under current directory C:\gg
- Parameter files C:\gg\dirprm: created
- Report files C:\gg\dirrpt: created
- Checkpoint files C:\gg\dirchk: created
- Process status files C:\gg\dirpcs: created
- SQL script files C:\gg\dirsql: created
- Database definitions files C:\gg\dirdef: created
- Extract data files C:\gg\dirdat: created
- Temporary files C:\gg\dirtmp: created
- Veridata files C:\gg\dirver: created
- Veridata Lock files C:\gg\dirver\lock: created
- Veridata Out-Of-Sync files C:\gg\dirver\oos: created
- Veridata Out-Of-Sync XML files C:\gg\dirver\oosxml: created
- Veridata Parameter files C:\gg\dirver\params: created
- Veridata Report files C:\gg\dirver\report: created
- Veridata Status files C:\gg\dirver\status: created
- Veridata Trace files C:\gg\dirver\trace: created
- Stdout files C:\gg\dirout: created
1.4 创建用户(源端及目标端均要执行):
- SQL>create user ggs identified by ggs default tablespace users temporary tablespace temp;
- SQL>grant connect,resource,dba,unlimited tablespace to ggs;
1.5 开启表级supplemental logging
- GGSCI (ogg1) 1> dblogin userid ggs password ggs
- GGSCI (ogg1) 2> add trandata ggs.*
1.6 配置mgr(源端及目标端均要执行):
- GGSCI (ogg1) 3> edit param mgr
- port 7809
- GGSCI (ogg1) 4> start mgr
1.7 配置源端复制队列
- GGSCI (ogg1) 5> add extract ext1,tranlog,begin now
- GGSCI (ogg1) 6>add rmttrail C:\gg\dirdat\lt extract ext1
- GGSCI (ogg1) 7> edit param ext1
- extract ext1
- userid ggs,password ggs
- rmthost 192.168.6.20, mgrport 7809
- rmttrail c:\gg\dirdat\lt
- dynamicresolution
- gettruncates
- table ggs.*;
参数说明:
- extract ext1 --抽取进程名为ext1
- userid ggs,password ggs --连接SourceDB的账号密码
- rmthost 192.168.6.20, mgrport 7809 --远程主机地址及服务端口(TargetDB)
- rmttrail c:\gg\dirdat\lt --远程队列的位置(TargetDB)
- dynamicresolution --优化参数,动态分析表结构
- gettruncates --是否抓取Truncate的数据
- table ggs.*; --配置抽取的table
- GGSCI (ogg1) 8> start ext1
- GGSCI (ogg1) 9> info all
- Program Status Group Lag Time Since Chkpt
- MANAGER RUNNING
- EXTRACT RUNNING EXT1 00:00:00 00:00:39
ABENDED 或 STOPPED 请查看c:\gg\ggserr.log
2.TargetDB配置:
2.1配置目标端同步队列:
- GGSCI (ogg2) 2> ADD replicat rep1 EXTTRAIL c:\gg\dirdat\lt,nodbcheckpoint
- GGSCI (ogg2) 3> edit param rep1
输入如下内容:
- replicat rep1
- userid ggs,password ggs
- assumetargetdefs
- reperror default,discard
- discardfile c:\gg\rep1_dis.log,append,megabytes 100
- map ggs.*, target ggs.*;
参数说明:
- replicat rep1 --复制进程名称
- userid ggs,password ggs --登陆targetDB的账号密码
- assumetargetdefs --两侧DB数据结构一致则使用此参数
- reperror default,discard --复制出错,则继续,错误放进discardfile中
- discardfile c:\gg\rep1_dis.log,append,megabytes 100 --以追加模式将错误信息写入rep1_dis.log文件,最大100m
- map ggs.*, target ggs.*; --源表与目标表对应
- GGSCI (ogg2) 4> start mgr
- GGSCI (ogg2) 5> start rep1
- GGSCI (ogg2) 6> info all
- Program Status Group Lag Time Since Chkpt
- MANAGER RUNNING
- REPLICAT RUNNING REP1 00:00:00 92:06:53
此时使用ggs用户登录后新建一张表(两边均需要操作):
SQL> create table tab_emp (id number primary key,name varchar2(10));
SourceDB 进行删除updater,insert,delete操作,查看targetDB的变化。