目录
源端配置
数据库起归档
安装OGG
创建ogg管理用户
配置OGG
添加附加日志
添加checkpoint
管理进程配置
抽取进程配置
投递进程配置
目标端配置
安装OGG
创建ogg管理用户
配置OGG
添加checkpoint
管理进程配置
源端启动进程
初始化目标端数据
应用进程配置
启动目标端应用进程
此文档源端目标端都是oracle 11g
#备份
SQL> create pfile='/app/oracle/init_orcldb20190923.ora' from spfile;
#开启ORACLE归档模式,设置日志模式
SQL> shutdown immediate;
SQL> startup mount;
#集群的话,实例在每个节点都要是mount状态
SQL> alter database archivelog;
SQL> alter database force logging;
SQL> alter database add supplemental log data;
SQL> alter database open;
#设置源上的数据库的FORCE LOGGING
FORCE LOGGING:简言之,强制记录日志,即对数据库中的所有操作都产生日志信息,并将该信息写入到联机重做日志文件。
SQL> select force_logging from v$database;
FOR
---
NO
SQL> ALTER DATABASE FORCE LOGGING;
数据库已更改。
SQL> select force_logging from v$database;
FOR
---
YES
#切换日志,使更改生效
SQL> alter system switch logfile;
系统已更改。
#打开数据库级别的补充日志(supplemental Log)
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO
SQL> alter database add supplemental log data;
数据库已更改。
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
数据库已更改。
#回收站功能会影响同步,需要关闭回收站
SQL>alter session set recyclebin=off;
SQL>alter system set recyclebin=off DEFERRED;
见另一篇:https://blog.csdn.net/weixin_41229271/article/details/98888847
在源端对应数据库实例下创建ogg管理用户
create user ggs identified by 123456 default tablespace oggtbs;
grant connect,resource,unlimited tablespace to ggs;
grant execute on utl_file to ggs;
grant select any dictionary,select any table to ggs;
grant alter any table to ggs;
grant flashback any table to ggs;
grant execute on DBMS_FLASHBACK to ggs;
grant EXEMPT ACCESS POLICY to ggs;
grant dba to ggs;
exec dbms_goldengate_auth.grant_admin_privilege('ggs');
进入ogg控制台,测试用户是否创建成功
[oracle@source ~]$ cd /mis_databak/bak/oggs/
[oracle@source oggs]$ ./ggsci
GGSCI (source ) 2> dblogin userid ggs,password 123456
Successfully logged into database.
添加所需同步的表的附加日志,示例
GGSCI (source ) 2>ADD TRANDATA USERNAME.TABLE_NAME
GGSCI (source) 2> dblogin userid ggs,password 123456
#添加GoldenGate的checkpoint表
GGSCI (source) 4> edit PARAMS GLOBALS
MGRSERVNAME GGMGR
checkpointtable ggs.checkpoint
GGSCI (source) 4> add checkpointtable ggs.checkpoint
Successfully created checkpoint table ggs.checkpoint.
GGSCI (source) 3> edit param mgr
#端口号
PORT 7809
#允许端口范围
DYNAMICPORTLIST 7801-8200
#自启抽取进程
AUTOSTART ER *
#重启抽取进程,每三分钟一个 重复五次
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
#删除超过三天的处理过的投递文件
PURGEOLDEXTRACTS /ggs/dirdat/*,usecheckpoints, minkeepdays 3
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
GGSCI (source) 3> start mgr
GGSCI (source) 9> edit param EX_TEST
extract EX_TEST
DYNAMICRESOLUTION
SETENV (ORACLE_SID="ORCL1")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID ggs, password 123456
REPORT AT 01:59
REPORTROLLOVER AT 02:00
CACHEMGR, CACHESIZE 256MB
DBOPTIONS ALLOWUNUSEDCOLUMN
WARNLONGTRANS 3h,CHECKINTERVAL 5m
EXTTRAIL ./dirdat/eh
NUMFILES 6000
EOFDELAYCSECS 30
GETTRUNCATES
TRANLOGOPTIONS DBLOGREADER
TRANLOGOPTIONS DBLOGREADERBUFSIZE 1048576
BR BRINTERVAL 2H , BRDIR BR
GETUPDATEBEFORES
NOCOMPRESSDELETES
#按表同步
#TABLE USERNAME.TABLENAME;
#按用户同步
#排除用户下某一张表
#TABLEEXCLUDE USERNAME.TABLE1;
#同步用户下的所有表
TABLE USERNAME.*;
GGSCI (source) 5> view params EX_TEST
增加一个抽取进程EX_HJ_G,名字可以根据需要修改
GGSCI (source) 6> add extract EX_TEST,tranlog,THREADS 2, begin now
EXTRACT added.
将EX_EMP抽取的源数据变更数据trail写到该文件夹
GGSCI (source) 7> add exttrail ./dirdat/eh,extract EX_TEST
EXTTRAIL added.
GGSCI (source) 8> edit params PM_TEST
extract PM_TEST
SETENV (ORACLE_SID="ORCL1")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID ggs, password 123456
REPORT AT 01:59
REPORTROLLOVER AT 02:00
CACHEMGR, CACHESIZE 256MB
FLUSHCSECS 30
NUMFILES 6000
EOFDELAYCSECS 30
#目标端ip地址
RMTHOST 192.168.1.1,MGRPORT 7809, TCPBUFSIZE 100000, TCPFLUSHBYTES 300000
RMTTRAIL /ggt/dirdat/ph
GETTRUNCATES
PASSTHRU
DYNAMICRESOLUTION
GETUPDATEBEFORES
NOCOMPRESSDELETES
#按表同步
#TABLE USERNAME.TABLENAME;
#按用户同步
#排除用户下某一张表
#TABLEEXCLUDE USERNAME.TABLE1;
#同步用户下的所有表
TABLE USERNAME.*;
GGSCI (source) 9> view params PM_TEST
GGSCI (source) 10> add extract PM_TEST,exttrailsource ./dirdat/eh
EXTRACT added.
GGSCI (source) 11> add rmttrail /ggt/dirdat/ph,extract PM_TEST
RMTTRAIL added.
见另一篇:https://blog.csdn.net/weixin_41229271/article/details/98888847
在目标端对应数据库实例下创建ogg管理用户
create user ggt identified by 123456 default tablespace oggtbs;
grant connect,resource,unlimited tablespace to ggt;
grant execute on utl_file to ggt;
grant select any dictionary,select any table to ggt;
grant alter any table to ggt;
grant flashback any table to ggt;
grant execute on DBMS_FLASHBACK to ggt;
grant EXEMPT ACCESS POLICY to ggt;
grant dba to ggt;
exec dbms_goldengate_auth.grant_admin_privilege('ggt');
进入ogg控制台,测试用户是否创建成功
[oracle@target~]$ cd /mis_databak/bak/oggs/
[oracle@target oggt]$ ./ggsci
GGSCI (target) 2> dblogin userid ggt,password 123456
Successfully logged into database.
GGSCI (target) 1> dblogin userid ggt,password 123456
Successfully logged into database.
GGSCI (target) 2> edit PARAMS GLOBALS
MGRSERVNAME GGMGR
checkpointtable ggt.checkpoint
GGSCI (target) 4> add checkpointtable ggt.checkpoint
Successfully created checkpoint table ggt.checkpoint.
GGSCI (target) 5> edit param mgr
PORT 7809
DYNAMICPORTLIST 7801-8200
AUTOSTART REPLICAT *
AUTORESTART REPLICAT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS /ggt/dirdat/*,usecheckpoints, minkeepdays 3
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
GGSCI (target) 7> start mgr
Manager started.
在源端启动抽取进程和投递进程,开始向目标端正常投递日志文件。
注:本文档基于真实环境进行配置操作,目标端数据初始化使用impdp数据浆泵根据scn号导出数据,然后在目标端导入。仅测试几张表的话,在源端和目标端分别创建即可。
#查询SCN号
select current_scn from v$database;
16543601519172
#源端导出数据
expdp system/123456@orcl1 cluster=no parallel=6 filesize=20G dumpfile=orcl1_db_20190923_%U.dmp logfile=orcl1_db_20190923.log SCHEMAS=USERNAME compression=ALL flashback_scn=16543601519172
#目标端导入数据
impdp system/123456@target directory=DATA_PUMP cluster=no parallel=6 dumpfile=orcl1_db_20190923_%U.dmp logfile=imp_orcl1_db_20190923.log SCHEMAS=USERNAME DATA_OPTIONS=SKIP_CONSTRAINT_ERRORS
GGSCI (target) 4> edit param RE_TEST
replicat RE_TEST
DYNAMICRESOLUTION
SETENV (ORACLE_SID="orcl2")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID ggt, password 123456
REPORT AT 01:59
REPORTROLLOVER AT 02:00
CACHEMGR, CACHESIZE 256MB
REPERROR DEFAULT,ABEND
DISCARDFILE ./dirrpt/RE_TEST.dsc,APPEND,MEGABYTES 10
DISCARDROLLOVER AT 06:00
GETTRUNCATES
NUMFILES 5000
EOFDELAYCSECS 30
ASSUMETARGETDEFS
ALLOWNOOPUPDATES
GETUPDATEBEFORES
#map后为源端用户名表名,target后为目标端对应用户名表名
map USERNAME.*, target USERNAME.*;
GGSCI (target) 8> view param RE_TEST
GGSCI (target) 9> add replicat RE_TEST, exttrail /ggt/dirdat/ph,CHECKPOINTTABLE ggt.checkpoint
REPLICAT added.
在数据初始化完成之后,根据数据导出时的scn号启动应用进程
start RE_TEST aftercsn 16543601519172
配置完成。