对于不同数据库类型的业务系统,为了对接业务,很多时候需要做数据同步处理,Goldengate异构同步可以比较灵活处理这些问题,该方案描述了异构同步的具体配置步骤。
ORACLE源库配置准备工作:
1)开启附加日志
select supplemental_log_data_min from v$database;
SUPPLEME
---------------
NO
alter database add supplemental log data;
select supplemental_log_data_min from v$database;
SUPPLEME
---------------
YES
2)开户归档(已经是归档模式,省略)
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/arch
SQL> alter database open;
3)创建OGG同步用户:
create user goldengate identified by goldengate default tablespace users;
grant dba to goldengate;
--------源库操作(oracle端):
1源端删除抽取,传输进程:
dblogin userid goldengate, password goldengate
--增加待同步表的附加日志:
add trandata MW_APP. DYT_DATALOSTRECORD
创建抽取进程相关GGLOG日志目录:
mkdir –p /ogg/gglog/e_MW_APP/
增加新的抽取进程:
add extract e_MW_APP, tranlog, begin now
add exttrail /ogg/gglog/e_MW_APP/ex, extract e_MW_APP,megabytes 200
2,删除并增加传输进程:
add extract p_MW_APP, exttrailsource /ogg/gglog/e_MW_APP/ex
add rmttrail /ogg/gglog/MW_APP/re, extract p_MW_APP, megabytes 200
3在源端启动抽取进程前,先做以下操作:
alter extract p_MW_APP,begin now --让传输进程从此刻开始启动传输数据
start e_MW_APP
创建要同步的表的定义(重要)
1. #创建参数文件
GGSCI (pos300-db01) 10> edit param defgen
defsfile ./dirdef/MW_APP.def
userid goldengate, password goldengate
table MW_APP.*;
#生成表定义文件
./defgen paramfile ./dirprm/defgen.prm
#传至目标库目录
scp /ogg/software/dirdef/MW_APP.def [email protected]:/ogg/software/dirprm
--------目标库(MYSQL端)
4删除复制进程和检查点表:
目标库为Mysql, 同oracle与oracle之间的同步略有区别
1)创建用户和待同步库
mysql> GRANT ALL PRIVILEGES ON `MW_APP`.* TO root@'%' IDENTIFIED BY ‘root’;
mysql>create database MW_APP;
2)创建目录
GGSCI (zoop300) 1> create subdirs
Creating subdirectories under current directory /home/mysql
Parameter files /goldengate/dirprm: created
Report files /goldengate/dirrpt: created
Checkpoint files /goldengate/dirchk: created
Process status files /goldengate/dirpcs: created
SQL script files /goldengate/dirsql: created
Database definitions files /goldengate/dirdef: created
Extract data files /goldengate/dirdat: created
Temporary files /goldengate/dirtmp: created
Stdout files /goldengate/dirout: created
mkdir –p /ogg/gglog/MW_APP/
3)配置管理进程
GGSCI (zoop300) 3> edit params mgr
加入:port 7809
GGSCI (zoop300) 4> start mgr
Manager started.
GGSCI (zoop300) 3> info mgr
Manager is running
4)配置检查点及全局
GGSCI (zoop300) 4> dblogin sourcedb MW_APP userid root password root
GGSCI (zoop300) 5> add checkpointtable MW_APP.checkpoint_table
GGSCI (zoop300) 6> edit params ./GLOBALS
checkpointtable MW_APP.checkpoint_table
5)配置replicat进程
GGSCI (zoop300) 8> add replicat r_MW_APP ,exttrail /ogg/gglog/MW_APP/re,checkpointtable MW_APP.checkpoint_table
编辑replicat进程
edit params r_MW_APP
--加入下列参数
replicat r_MW_APP
targetdb MW_APP userid root password root
handlecollisions
sourcedefs /ogg/software/dirprm/MW_APP.def
discardfile /ogg/software/dirrpt/dcr1.dsc,purge
map MW_APP.DYT_DATALOSTRECORD,target MW_APP.DYT_DATALOSTRECORD;
启动进程:
GGSCI (zoop300) 9> start dcr1
4、测试数据同步
附录:
--各进程配置
-E
extract e_MW_APP
SETENV (ORACLE_HOME = "/u01/oracle")
SETENV (ORACLE_SID = "idoracle")
SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")
userid goldengate,password goldengate
exttrail /ogg/gglog/e_MW_APP/ex
discardfile /ogg/software/dirrpt/e_MW_APP.dsc,append
TRANLOGOPTIONS DBLOGREADER
dynamicresolution
table MW_APP.DYT_DATALOSTRECORD;
-P
extract p_MW_APP
rmthost 192.168.1.241,mgrport 7809
passthru
rmttrail /ogg/gglog/MW_APP/re
table MW_APP.DYT_DATALOSTRECORD;
-R
replicat r_MW_APP
targetdb MW_APP userid root password root
handlecollisions
sourcedefs /ogg/software/dirprm/MW_APP.def
discardfile /ogg/software/dirrpt/dcr1.dsc,purge
map MW_APP.DYT_DATALOSTRECORD,target MW_APP.DYT_DATALOSTRECORD;