一、配置环境
source target
IP地址 192.168.184.220 192.168.184.221
操作系统 oracle linux 6.8 oracle linux 6.8
数据库软件 ORACLE 11.2.0.4 ORACLE 12.2.0.1
实例名 ogg1 ogg2
OGG软件 122022_fbo_ggs_Linux_x64_shiphome.zip 122022_fbo_ggs_Linux_x64_shiphome.zip
OGG安装目录 /u01/ogg12 /u01/ogg12
安装用户 oracle oracle
OGG管理用户 ogg ogg
待同步的用户 bing bing
二、OGG安装准备工作
1、分别在source及target库安装数据库软件
2、source端操作:
开启归档:
SQL>alter database archivelog
开启强制日志记录:
SQL>alter database force logging
开启附加日志:
SQL>alter database add supplemental log data;
设置ogg参数:
SQL>alter system set enable_goldengate_replication=true scope=both sid='*';
创建OGG单独使用的表空间:
SQL>create tablespace ogg_tbs datafile '+DATA' size 5G autoextend on next 64m;
创建ogg管理用户:
SQL>create user ogg identified by ogg$123 default tablespace ogg_tbs;
赋予权限:
SQL>grant connect, resource,CREATE SESSION to ogg;
SQL>exec dbms_goldengate_auth.grant_admin_privilege('ogg');
SQL>exec dbms_goldengate_auth.grant_admin_privilege(grantee=>'ogg');
SQL>grant select any dictionary to ogg;
配置tns:
OGG1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.184.220)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ogg1)
)
)
3、target端操作:
设置ogg参数:
SQL>alter system set enable_goldengate_replication=true scope=both sid='*';
创建OGG单独使用的表空间:
SQL>create tablespace ogg_tbs datafile '+DATA' size 5G autoextend on next 64m;
创建ogg管理用户:
SQL>create user ogg identified by ogg$123 default tablespace ogg_tbs;
赋予权限:
SQL>grant connect, resource,CREATE SESSION to ogg;
SQL>exec dbms_goldengate_auth.grant_admin_privilege('ogg');
SQL>exec dbms_goldengate_auth.grant_admin_privilege(grantee=>'ogg');
SQL>grant select any dictionary to ogg;
配置tns:
OGG2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.184.221)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ogg2)
)
)
三、ogg软件安装(source、target)
上传、解压ogg安装包并修改属主:
unzip 122022_fbo_ggs_Linux_x64_shiphome.zip
chown -R oracle:oinstall 122022_fbo_ggs_Linux_x64_shiphome
修改oracle坏境变量
1、静默安装:
cd /fbo_ggs_Linux_x64_shiphome/Disk1/response/
view plain copy
INSTALL_OPTION=ORA11g ----11g数据库选择ORA11g,12C选择ORA12c
SOFTWARE_LOCATION=/u01/ogg12 ----ogg安装目录
开始安装
/fbo_ggs_Linux_x64_shiphome/Disk1/runInstaller -silent -nowait -responseFile
2、图形安装(建议)
export DISPLAY=192.168.184.1:0.0
/fbo_ggs_Linux_x64_shiphome/Disk1/runInstaller
在安装过程中需要自行选择对应的数据库版本以及ogg软件安装路径
四、OGG配置
1、证书及抽取表配置(source)
创建OGG认证证书文件用于隐藏口令登录
cd /u01/ogg12
./ggsci
GGSCI > add credentialstore
GGSCI >alter credentialstore add user ogg@ogg1,password ogg$123 alias ogg1
测试登录
GGSCI (ogg1) 2> dblogin useridalias ogg1
Successfully logged into database.
配置抽取的表加入trandata
GGSCI (ogg1 as ogg@ogg1) 3> add trandata schema.tablename --可通过schema.*代表添加该用户下所有表
查看抽取的表信息
GGSCI (ogg1 as ogg@ogg1) 4> info trandata schema.tablename
添加检查点表
GGSCI (ogg1 as ogg@ogg1) 5>add checkpointtable ogg.checkpoint
2、MGR进程配置(source)
GGSCI > edit params ./GLOBALS
ENABLEMONITORING
CHECKPOINTTABLE ogg.checkpoint
GGSCHEMA ogg
配置mgr进程
GGSCI>edit param mgr
PORT 7809
DYNAMICPORTLIST 7810-7820
管理mgr进程命令
GGSCI> START MGR
GGSCI> info MGR
GGSCI> stop MGR
3、配置extract抓取进行:(source)
GGSCI (ogg1) 4> add extract ext,tranlog,begin now
GGSCI (ogg1) 5> add exttrail ./dirdat/ea,extract ext
GGSCI (ogg1) 5> add exttrail ./dirdat/ea,extract ext,THREADS 2 (RAC环境使用)
GGSCI (ogg1) 6> edit params ext
EXTRACT ext
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
USERIDALIAS ogg1
TRANLOGOPTIONS DBLOGREADER --rac时使用
FETCHOPTIONS NOUSESNAPSHOT
GETTRUNCATES
EXTTRAIL ./dirdat/ea
DISCARDFILE ./dirrpt/ea.dsc, APPEND, MEGABYTES 40
WARNLONGTRANS 1H, CHECKINTERVAL 5M
CACHEMGR CACHESIZE 1024MB, CACHEDIRECTORY ./dirtmp
LOGALLSUPCOLS
NOCOMPRESSUPDATES
UPDATERECORDFORMAT FULL
REPORTCOUNT EVERY 2 SECONDS, RATE
table bing.*;
启动extract进程
GGSCI (ogg1) 7> start extract ext
管理extract抓取进程命令
GGSCI > start extract ext –启动ext进程
GGSCI > stop extract ext –关闭ext进程
GGSCI > kill extract ext --强制停止ext进程
GGSCI > info ext --查看进程参数信息
GGSCI > stats ext --查看进程运行信息
GGSCI > view report ext ---查看运行报告
4、配置pump投递进程(source)
GGSCI (ogg1) 7>add extract pump,exttrailsource ./dirdat/ea
GGSCI (ogg1) 8>add rmttrail ./dirdat/pa,extract pump
GGSCI (ogg1) 9>edit params pump
extract pump
rmthost 192.168.184.221,mgrport 7809,compress
rmttrail ./dirdat/pa
passthru
table bing.*;
5、管理pump投递进程
GGSCI > start extract pump –启动pump进程
GGSCI > stop extract pump –关闭pump进程
GGSCI > kill extract pump --强制停止pump进程
GGSCI > info pump --查看进程参数信息
GGSCI > stats pump --查看进程运行信息
GGSCI > view report pump ---查看运行报告
5、target端配置证书(target)
创建OGG认证证书文件用于隐藏口令登录
cd /u01/ogg12
./ggsci
GGSCI > add credentialstore
GGSCI >alter credentialstore add user ogg@ogg2,password ogg$123 alias ogg2
测试登录
GGSCI (ogg1) 2> dblogin useridalias ogg2
Successfully logged into database.
6、配置globals参数(target)
GGSCI (ogg2 as ogg@ogg2) 4>edit params ./GLOBALS
ggschema ogg
enablemonitoring
checkpointtable ogg.chkpt
7、添加检查点表(target)
GGSCI (ogg2 as ogg@ogg2) 5>add checkpointtable ogg.chkpt
Successfully created checkpoint table ogg.chkpt.
8、添加replicat应用进程及配置参数
GGSCI (ogg2 as ogg@ogg2) 8> add replicat rep,exttrail ./dirdat/pa checkpointtable ogg.chkpt
REPLICAT added.
GGSCI (ogg2 as ogg@ogg2) 9> edit params rep
replicat rep
setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
assumetargetdefs
discardfile ./dirout/RAMER.DSC, purge
USERIDALIAS ogg2
map bing.*, target bing.*;
GGSCI > start extract rep –启动rep进程
GGSCI > stop extract rep –关闭rep进程
GGSCI > kill extract rep --强制停止e1进程
GGSCI > info rep --查看进程参数信息
GGSCI > stats rep --查看进程运行信息
GGSCI > view report rep ---查看运行报告
9、初始化数据(source)
原库查询出scn号
select current_scn from v$database;
SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;
使用exp或expdp导出数据
对于导出用户需要具备DBMS_FLASHBACK包的执行权限
GRANT EXECUTE ON DBMS_FLASHBACK TO bing;
exp bing/bing flashback_SCN=1198357 file=export.dmp
expdp bing/bing directory=dump dumpfile=source.dmp schemas=bing flashback_scn=1189672
10、初始化数据(target)
将source库dmp拷贝到target库
imp bing/bing file=export.dmp full=y
impdp bing/bing directory=dump dumpfile=source.dmp schemas=bing
11、启动pump进程(source)
GGSCI>GGSCI (ogg1 as ogg@ogg1) 30> start pump
Sending START request to MANAGER ...
EXTRACT PUMP starting
12、target库启动replicat进程
GGSCI>start replicat rep,aftercsn 1198357
13、配置DDL方式OGG
赋予权限(source)
SQL>grant execute on utl_file to ggs;
SQL>@marker_setup.sql --按要求输入ogg用户
SQL>@ddl_setup.sql
SQL>@role_setup.sql
SQL>@ddl_enable.sql
SQL>@?/rdbms/admin/dbmspool.sql
SQL>@ddl_pin.sql ggs
修改extract进程的params参数添加“ddl include all”(source)
GGSCI (ogg1) 6> edit params ext
EXTRACT ext
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
USERIDALIAS ogg1
--USERIDALIAS pmsprod
TRANLOGOPTIONS DBLOGREADER
FETCHOPTIONS NOUSESNAPSHOT
GETTRUNCATES
EXTTRAIL ./dirdat/ea
DISCARDFILE ./dirrpt/ea.dsc, APPEND, MEGABYTES 40
WARNLONGTRANS 1H, CHECKINTERVAL 5M
CACHEMGR CACHESIZE 1024MB, CACHEDIRECTORY ./dirtmp
LOGALLSUPCOLS
NOCOMPRESSUPDATES
UPDATERECORDFORMAT FULL
REPORTCOUNT EVERY 2 SECONDS, RATE
DDL INCLUDE ALL ---DDL时开启
table bing.*;
GGSCI (ogg1) 6> edit params pump
extract pump
rmthost 192.168.184.221,mgrport 7809,compress
rmttrail ./dirdat/pa
passthru
table bing.*;
DDL INCLUDE ALL ---DDL时开启
添加完成后重启进程
target端修改replicat进程的params文件(target)
添加"ddl include all"和"ddlerror default ignore retryop maxretries 3 retrydelay 5" 参数
GGSCI (ogg2 as ogg@ogg2) 9> edit params rep
replicat rep
setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
assumetargetdefs
discardfile ./dirout/RAMER.DSC, purge
USERIDALIAS ogg2
map bing.*, target bing.*;
ddl include all ---开启ddl同步,还需要配合执行@ddl脚本
ddlerror default ignore retryop maxretries 3 retrydelay 5 ---开启ddl同步
重启replicat进程