ogg12.2.0.1 仍旧可以支持oracle 11.2.0.4,但是需要打补丁17030189,且舍弃了一些参数。针对oracle11.2版本,个人建议还是用早期版本
注意点:保证捕获开始点和初始化数据加载点 数据的一致。
此实验以配置Integrated extract和Integrated replicate方式进行配置
环境:
ogg版本:121210_fbo_ggs_Linux_x64_shiphome.zip
oracle版本:11.2.0.4
操作系统:RHEL6.5x64
2台服务器安装好数据库软件及实例,实例名可以不一样。此实验使用相同的ORACLE_SID
环境变量: vim ~oracle/.bash_profile
#export ORACLE_OWNER=oracle
#export ORACLE_TERM=xterm
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
export ORACLE_SID=zytk
export LANG=en_US
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=/u01/app/oracle/ogg:$OR:$ORACLE_HOME/lib:/lib:/usr/lib
export EDITOR=/usr/bin/vim
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
trail文件最好单独磁盘,以使得对系统影响最小。trail磁盘大小=每小时日志量*trailfile保存时间*0.4
完整捕获及重演模式消耗的是SGA中的内存,需要配置
此实验OGG软件安装在oracle用户下。
解压软件,运行runInstall.sh脚本。相比较之前版本,省略了create subdirs,且mgr可在安装过程中配置。
software location:修改为OGG的安装路径
[oracle@ogg1 ogg]$ sqlplus / as sysdba
SQL> create tablespace tbs_ogg datafile '/OracleData/zytk/tbs_ogg01.dbf' size 10M autoextend on next 10M;
SQL> create user ogg identified by ogg default tablespace tbs_ogg;
SQL> grant dba to ogg;
[oracle@ogg1 ogg]$ sqlplus / as sysdba
SQL> alter database force logging;
SQL> alter database add supplemental log data;
SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;
LOG_MODE SUPPLEMENTAL_LOG FORCE_
------------------------ ---------------- ------
ARCHIVELOG YES YES
SQL> alter system set enable_goldengate_replication=true scope=both; --(源端即可)
SQL> alter system switch logfile;
SQL> EXEC DBMS_GOLDENGATE_AUTH.GRANT_ADMIN_PRIVILEGE('ogg');
alter system set UNDO_RETENTION=86400; ----非必须,但有利于数据捕获应用
可选:一般出于安全考虑建议使用别名登录
创建登录别名,创建后可以用【dblogin useridalias 别名】进行登录
[oracle@ogg1 ogg]$ ./ggsci
GGSCI (ogg1.localdomain) 2> add credentialstore
GGSCI (ogg1.localdomain) 3> alter credentialstore add user ogg alias oggalias
此实验未用到
[oracle@ogg1 ~]$ cd $GG_HOME
[oracle@ogg1 ogg]$ ./ggsci
GGSCI (ogg1.localdomain) 2> stop mgr !
GGSCI (ogg1.localdomain) 4> edit params mgr
PORT 7809
DYNAMICPORTLIST 7840-7914
AUTOSTART ER *
AUTORESTART ER *, RETRIES 3, WAITMINUTES 5, RESETMINUTES 60
--USERIDALIAS oggalias
USERID ogg, PASSWORD ogg
PURGEOLDEXTRACTS /u01/app/oracle/ogg/dirdat/*, USECHECKPOINTS, MINKEEPDAYS 7
LAGREPORTHOURS 1
LAGINFOMINUTES 3
LAGCRITICALMINUTES 5
MANAGER进程参数配置说明:
PORT:指定服务监听端口;默认端口为7809
DYNAMICPORTLIST:动态端口:可以制定最大256个可用端口的动态列表,当指定的端口不可用时,管理进程将会从列表中选择一个可用的端口,源端和目标段的Collector、Replicat、GGSCI进程通信也会使用这些端口;
COMMENT:注释行,也可以用--来代替;
AUTOSTART:指定在管理进程启动时自动启动哪些进程;
AUTORESTART:自动重启参数设置:本处设置表示每3分钟尝试重新启动所有EXTRACT进程,共尝试5次;
PURGEOLDEXTRACTS:定期清理trail文件设置:本处设置表示对于超过3天的trail文件进行删除。
LAGREPORT、LAGINFO、LAGCRITICAL:
定义数据延迟的预警机制:本处设置表示MGR进程每隔1小时检查EXTRACT的延迟情况,如果超过了30分钟就把延迟作为信息记录到错误日志中,如果延迟超过了45分钟,则把它作为警告写到错误日志中。
USERIDALIAS:需要使用ADD CREDENTIALSTORE
ALTER CREDENTIALSTORE ADD USER ogg ALIAS oggalias
此处实验以INTEGRATED EXTRACT方式,而非经典模式。
该模式需要配置数据库streams_pool_size的值
GGSCI (ogg1.localdomain) 9> edit params ext1
EXTRACT ext1
dynamicresolution
--SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
--SETENV (ORACLE_HOME = '/u01/app/oracle/product/11.2.0.4/dbhome_1')
--SETENV (ORACLE_SID = 'zytk')
USERID ogg, PASSWORD ogg
TRANLOGOPTIONS INTEGRATEDPARAMS (MAX_SGA_SIZE 164)
LOGALLSUPCOLS
UPDATERECORDFORMAT COMPACT
EXTTRAIL ./dirdat/lt
TABLE zytk.*;
TRANLOGOPTIONS INTEGRATEDPARAMS (max_sga_size 300, _LOGMINER_READ_BUFFERS 128, parallelism 2) ---也可以设置并行度
GGSCI (ogg1.localdomain) 13> dblogin userid ogg, password ogg
Successfully logged into database.
GGSCI (ogg1.localdomain as ogg@zytk) 14> register extract ext1 database
Extract EXT1 successfully registered with database at SCN 1017765
GGSCI (ogg1.localdomain as ogg@zytk) 15> ADD EXTRACT ext1, INTEGRATED TRANLOG,BEGIN now
GGSCI (ogg1.localdomain as ogg@zytk) 16> ADD EXTTRAIL ./dirdat/lt, EXTRACT ext1
参数说明:
GGSCI (ogg1.localdomain as ogg@zytk) 19> edit params extdp1
EXTRACT extdp1
USERID ogg, PASSWORD ogg
RMTHOST ogg2.localdomain, MGRPORT 7809, KEYNAME securekey2
RMTTRAIL /u01/app/oracle/ogg/dirdat/rt
---- PASSTHRU
TABLE zytk.*;
PASSTHRU ---如果源和目标端数据定义一致,则添加该参数
GGSCI (ogg1.localdomain as ogg@zytk) 22> ADD EXTRACT extdp1, EXTTRAILSOURCE /u01/app/oracle/ogg/dirdat/lt, BEGIN now
GGSCI (ogg1.localdomain as ogg@zytk) 23> ADD RMTTRAIL /u01/app/oracle/ogg/dirdat/rt, EXTRACT extdp1
----mgr启动后,由于配置了autostart参数,其他extract进程也会随之启动,如果未启动查原因
GGSCI (ogg1.localdomain as ogg@zytk) 92> start mgr
Integrated Replicat Mode
GGSCI (ogg2.localdomain) 3> edit params ./GLOBALS
CHECKPOINTTABLE ogg.checkpoint
GGSCI (ogg2.localdomain) 3> exit
[oracle@ogg2 ogg]$ ./ggsci
GGSCI (ogg2.localdomain as ogg@zytk) 1> dblogin userid ogg, password ogg
GGSCI (ogg2.localdomain as ogg@zytk) 2> add checkpointtable ogg.checkpoint
GGSCI (ogg2.localdomain) 10> edit params rep1
REPLICAT rep1
DBOPTIONS INTEGRATEDPARAMS(parallelism 2)
dynamicresolution
USERID ogg, PASSWORD ogg
ASSUMETARGETDEFS
MAP zytk.*, TARGET zytk.*;
GGSCI (ogg2.localdomain) 13> add replicat rep1 integrated exttrail ./dirdat/rt , checkpointtable ogg.checkpoint
REPLICAT (Integrated) added
暂时别启动进程
此可以通过数据库本身的expdp、rman备份还原方式来完成,也可以通过ogg的初始数据加载方法进行,此实验用expdp方法实现。
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
1041649
[oracle@ogg1 ~]$ expdp zytk/zytk directory=dmp dumpfile=zytk01.dmp schemas=zytk flashback_scn=1041649
把导出的文件拷贝到目标端,进行还原
[oracle@ogg2 ~]$ impdp zytk/zytk directory=dmp dumpfile=zytk01.dmp schemas=zytk
----table_exists_action=truncate
启动目标端进程,并测试
GGSCI (ogg2.localdomain) 10> start replicat rep1,aftercsn 1041649
至此:12c单向复制已经完成
在实验基础上,先停止所有进程,注意停止进程时判断下进程是否完成。
由于使用的是Integrated extract和Integrated replicat模式,不使用基于触发器的DDL捕获。
GGSCI (ogg1.localdomain) 3> edit params ext1
EXTRACT ext1
dynamicresolution
--SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
--SETENV (ORACLE_HOME = '/u01/app/oracle/product/11.2.0.4/dbhome_1')
--SETENV (ORACLE_SID = 'zytk')
USERID ogg, PASSWORD ogg
TRANLOGOPTIONS INTEGRATEDPARAMS (MAX_SGA_SIZE 164)
DDL INCLUDE ALL, EXCLUDE OBJNAME ogg.*
LOGALLSUPCOLS
UPDATERECORDFORMAT COMPACT
EXTTRAIL ./dirdat/lt
TABLE zytk.*;
GGSCI (ogg2.localdomain) 1> edit params rep1
REPLICAT rep1
DBOPTIONS INTEGRATEDPARAMS(parallelism 2)
dynamicresolution
USERID ogg, PASSWORD ogg
ASSUMETARGETDEFS
DDL INCLUDE ALL, EXCLUDE OBJNAME ogg.*
MAP zytk.*, TARGET zytk.*;
DDLOPTIONS MAPSESSIONSCHEMA SRC1 TARGET DST1 ---如果一致可省略
一般用于经典模式的EXTRACT和REPLICAT模式
[oracle@ogg1 ~]$ cd $GG_HOME
[oracle@ogg1 ogg]$ sqlpluls / as sysdba
SQL> @marker_setup.sql; ----输入OGG用户,此为ogg
SQL> @ddl_setup.sql; ----输入OGG用户
SQL> @role_setup.sql; ----输入OGG用户
SQL> GRANT GGS_GGSUSER_ROLE TO ogg;
SQL> @ddl_enable.sql;
SQL> @?/rdbms/admin/dbmspool.sql; ----优化,可选
SQL> @ddl_pin ogg;
[oracle@ogg1 ogg]$ ./ggsci
GGSCI (ogg1.localdomain) 1> edit params ./GLOBALS
GGSCHEMA ogg
---replicat需要检查表
---CHECKPOINTTABLE ogg.chkpoint
EXTRACT参数:
DDL INCLUDE OBJNAME SRC.* INCLUDE OBJNAME SRC1.*
GETTRUNCATES
REPLICAT参数:
DDLOPTIONS MAPSESSIONSCHEMA SRC TARGET DST
基于实验二基础上完成
先关闭OGG所有进程,然后进程相关配置修改。
新增REPLICAT进程,修改原EXTRACT进程
GGSCI (ogg1.localdomain) 3> edit params ./GLOBALS
CHECKPOINTTABLE ogg.checkpoint
GGSCI (ogg1.localdomain) 3> exit
[oracle@ogg1 ogg]$ ./ggsci
GGSCI (ogg1.localdomain as ogg@zytk) 1> dblogin userid ogg, password ogg
GGSCI (ogg1.localdomain as ogg@zytk) 2> add checkpointtable ogg.checkpoint
GGSCI (ogg1.localdomain) 10> edit params rep2
REPLICAT rep2
DBOPTIONS INTEGRATEDPARAMS(parallelism 2)
DBOPTIONS SETTAG
dynamicresolution
USERID ogg, PASSWORD ogg
ASSUMETARGETDEFS
DDL INCLUDE ALL, EXCLUDE OBJNAME ogg.*
MAP zytk.*, TARGET zytk.*;
GGSCI (ogg1.localdomain) 13> add replicat rep2 integrated exttrail ./dirdat/rx , checkpointtable ogg.checkpoint
REPLICAT (Integrated) added
新增EXTRACT进程和DATA PUMP进程,修改REPLICAT进程。
GGSCI (ogg2.localdomain) 9> edit params ext1
EXTRACT ext2
dynamicresolution
--SETENV (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
--SETENV (ORACLE_HOME = '/u01/app/oracle/product/11.2.0.4/dbhome_1')
--SETENV (ORACLE_SID = 'zytk')
USERID ogg, PASSWORD ogg
TRANLOGOPTIONS INTEGRATEDPARAMS (MAX_SGA_SIZE 164)
TRANLOGOPTIONS EXCLUDETAG
DDL INCLUDE ALL, EXCLUDE OBJNAME ogg.*
LOGALLSUPCOLS
UPDATERECORDFORMAT COMPACT
EXTTRAIL ./dirdat/lx
TABLE zytk.*;
GGSCI (ogg2.localdomain) 15> dblogin userid ogg, password ogg
Successfully logged into database.
GGSCI (ogg2.localdomain as ogg@zytk) 16> register extract ext2 database
Extract EXT2 successfully registered with database at SCN 1096409.
GGSCI (ogg2.localdomain as ogg@zytk) 17> ADD EXTRACT ext2, INTEGRATED TRANLOG,BEGIN now
EXTRACT added.
GGSCI (ogg2.localdomain as ogg@zytk) 19> ADD EXTTRAIL ./dirdat/lx, EXTRACT ext2
EXTTRAIL added.
GGSCI (ogg2.localdomain as ogg@zytk) 24> edit params extdp2
EXTRACT extdp2
USERID ogg, PASSWORD ogg
RMTHOST ogg1.localdomain, MGRPORT 7809
RMTTRAIL /u01/app/oracle/ogg/dirdat/rx
TABLE zytk.*;
GGSCI (ogg2.localdomain as ogg@zytk) 25> ADD EXTRACT extdp2, EXTTRAILSOURCE /u01/app/oracle/ogg/dirdat/lx, BEGIN now
EXTRACT added.
GGSCI (ogg2.localdomain as ogg@zytk) 26> ADD RMTTRAIL /u01/app/oracle/ogg/dirdat/rx, EXTRACT extdp2
RMTTRAIL added.
GGSCI (ogg2.localdomain as ogg@zytk) 29> edit params rep1
REPLICAT rep1
DBOPTIONS INTEGRATEDPARAMS(parallelism 2)
DBOPTIONS SETTAG
dynamicresolution
USERID ogg, PASSWORD ogg
ASSUMETARGETDEFS
DDL INCLUDE ALL, EXCLUDE OBJNAME ogg.*
MAP zytk.*, TARGET zytk.*;
BATCHSQL ---针对类似的批量提交有显著的性能提高。。。。场景
extract:其他参数配置建议
WARNLONGTRANS 1H, CHECKINTERVAL 5M
STATOPTIONS REPORTFETCH
DISCARDFILE
DISCARDFILE ./dirrpt/extxx.dsc,APPEND,MEGABYTES 1024
replicat:其他参数配置建议
REPORT AT 01:59
REPERROR DEFAULT, ABEND
DBOPTIONS DEFERRORFCONST
DISARDFILE ./dirrpt/repya1.dsc, APPEND, MEGABYTES 1024
GGSCI (ogg1.localdomain as ogg@zytk35) 38> stop extract ext1
SQL> @ddl_disable;
SQL> @ddl_remove;
DDL replication removal script.
WARNING: this script removes all DDL replication objects and data.
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
Enter Oracle GoldenGate schema name:ogg
Working, please wait ...
Spooling to file ddl_remove_spool.txt
Script complete.
SQL> @marker_remove;
Marker removal script.
WARNING: this script removes all marker objects and data.
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
Enter Oracle GoldenGate schema name:ogg
PL/SQL procedure successfully completed.
Sequence dropped.
Table dropped.
Script complete.
ggsci命令行中支持history、!、fc命令显示历史执行过的语句
KILL {EXTRACT | REPLICAT} group_name ---杀死进程
stop er *
delete extract ext1
delete replicat rep1
unregister extract ext1 database
obey filename : 可以直接调用文件中的命令
mgr paramfile parameter_file [reportfile report_file] ---命令行模式启动mgr
? 可以用来调用变量
LAG EXTRACT ext_1
LAG EXTRACT pump_1
dumpddl
FLUSH SEQUENCE
list table *
CLEANUP CHECKPOINTTABLE
ADD TRACETABLE ora_trace --双向同步配置
history
FC n
GGSCI (ogg1.localdomain as ogg@zytk35) 10> VIEW GGSEVT ---显示错误日志
CHECKPARAMS ---测试语法
DBOPTIONS SETTAG --阻止循环replicat
DDL INCLUDE ALL, EXCLUDE OBJNAME hr.*
DDL INCLUDE OBJNAME fin.* EXCLUDE OBJNAME fin.ss