Administrator
Published on 2022-06-21 / 41 Visits
0
0

Oracle11gR2_使用GoldenGate配置单向同步

※1、机器清单

机器名ip系统版本DB版本SID
rac1(source)192.168.167.110CentOS release 6.8 (Final)oracle11G R2rac1
rac2(target)192.168.167.111CentOS release 6.8 (Final)oracle11G R2rac2

※2、软件搭建配置

#注明,两台机器都需要安装oracle实例
#安装包存放路径: /data/soft/fbo_ggs_Linux_x64_ora11g_64bit.tar
 
#创建工作目录
mkdir -p /data/ogg
tar xvf /data/soft/fbo_ggs_Linux_x64_ora11g_64bit.tar -C /data/ogg
 
#添加环境变量(请在末尾添加下面三条环境变量)
vim /home/oracle/.profileORA
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=/data/ogg:$PATH
export LD_LIBRARY_PATH=/data/ogg:$LD_LIBRARY_PATH
 
[root@k8scgsitdb soft]# su oracle
[oracle@k8scgsitdb soft]$ !source
source /home/oracle/.profileORA

※3、查询或修改归档模式(在源端和目标端都执行)

[oracle@k8scgsitdb soft]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 03:30:31 2022
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;
 
LOG_MODE                             SUPPLEMENTAL_LOG_DATA_MI FORCE_LOG
------------------------------------ ------------------------ ---------
NOARCHIVELOG                         NO                       NO                #此地方查询归档未打开,则操作下面步骤
 
SQL> shutdown immediate              #关闭数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount                   #非安装启动
ORACLE instance started.
 
Total System Global Area 6413680640 bytes
Fixed Size                  2265224 bytes
Variable Size            4043313016 bytes
Database Buffers         2348810240 bytes
Redo Buffers               19292160 bytes
Database mounted.
SQL> alter database archivelog;         #修改归档模式
 
Database altered.
 
SQL> alter database open;               #打开数据库提供服务
 
Database altered.
 
SQL> alter database force logging;      #开启强制日志模式
 
Database altered.
 
SQL> alter database add supplemental log data;
 
Database altered.
 
SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;
 
LOG_MODE                             SUPPLEMENTAL_LOG_DATA_MI FORCE_LOG
------------------------------------ ------------------------ ---------
ARCHIVELOG                           YES                      YES
 
SQL>

※3、配置复制用户与初始用户权限(两边机器都需要操作)

[root@rac1 ~]# su oracle
[oracle@rac1 root]$ source /home/oracle/.profileORA
[oracle@rac1 root]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.4.0 Production on Thu Apr 7 00:41:59 2022
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> alter system set enable_goldengate_replication=true scope=both;   #oracle 11.2.0.4之后的版本或者是oracle12.1.0.2才会有的参数,导致sequence与关联表同步不执行
 
System altered.
 
SQL> alter system set recyclebin=off DEFERRED;      #关闭回收站功能,否则同步会出现特别大延迟
 
System altered.
 
SQL> CREATE TABLESPACE ogg  datafile '/data/oracle/sit/datafile/ogg.dbf' SIZE 5G autoextend on EXTENT MANAGEMENT LOCAL;  #<<注意事项,需要表空间为自动扩展模式
CREATE TABLESPACE ogg  datafile '/data/oracle/sit/datafile/ogg.dbf' SIZE 5G autoextend on EXTENT MANAGEMENT LOCAL  
*   #本地机器已经创建过,提示已经存在
ERROR at line 1:
ORA-01543: tablespace 'OGG' already exists
 
 
SQL> create user ogg identified by ogg default tablespace ogg temporary tablespace temp;
create user ogg identified by ogg default tablespace ogg temporary tablespace temp
            *   #本地机器已经创建过,提示已经存在
ERROR at line 1:
ORA-01920: user name 'OGG' conflicts with another user or role name
 
 
SQL> grant connect,resource to ogg;
 
Grant succeeded.
 
SQL> grant create table,create sequence to ogg;
 
Grant succeeded.
 
SQL> grant execute on utl_file to ogg;
 
Grant succeeded.
 
SQL> grant connect,resource,unlimited tablespace to ogg;
 
Grant succeeded.
 
SQL> grant create session,alter session to ogg;
 
Grant succeeded.
 
SQL> grant select any dictionary,select any table to ogg;
 
Grant succeeded.
 
SQL> grant alter any table to ogg;
 
Grant succeeded.
 
SQL> grant flashback any table to ogg;
 
Grant succeeded.
 
SQL> grant execute on dbms_flashback to ogg;
 
Grant succeeded.

※4、开启DDL同步 (该步骤也是两端机器需要操作)

引导注释:创建一个专门传输的用户,规避使用owner用户权限过大,可以使权限控制在指定范围之内

[root@rac1 ~]# su oracle
[oracle@rac1 root]$ cd /data/ogg/
[oracle@rac1 ogg]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.4.0 Production on Thu Apr 7 00:44:35 2022
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> @marker_setup.sql      #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<执行第一个脚本                                 
 
Marker setup script
 
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.
NOTE: Stop all DDL replication before starting this installation.
 
Enter Oracle GoldenGate schema name:ogg        #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<输入创建的用户名字
 
 
Marker setup table script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to OGG
 
MARKER TABLE
--------------------------------------------------------------------------------
OK
 
MARKER SEQUENCE
--------------------------------------------------------------------------------
OK
 
Script complete.
SQL> @ddl_setup.sql    #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<执行第二个脚本
 
Oracle GoldenGate DDL Replication setup script
 
Verifying that current user has privileges to install DDL Replication...
 
You will be prompted for the name of a schema for the Oracle GoldenGate database objects.
NOTE: For an Oracle 10g source, the system recycle bin must be disabled. For Oracle 11g and later, it can be enabled.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
 
Enter Oracle GoldenGate schema name:ogg       #<<<<<<<<<<<<<<<<<<<<<<<<<<<<输入用户名字
 
Working, please wait ...
Spooling to file ddl_setup_spool.txt
 
Checking for sessions that are holding locks on Oracle Golden Gate metadata tables ...
 
Check complete.
 
 
 
 
 
 
 
 
 
 
 
Using OGG as a Oracle GoldenGate schema name.
 
Working, please wait ...
 
DDL replication setup script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to OGG
 
CLEAR_TRACE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
CREATE_TRACE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
TRACE_PUT_LINE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
INITIAL_SETUP STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDLVERSIONSPECIFIC PACKAGE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDLREPLICATION PACKAGE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDLREPLICATION PACKAGE BODY STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDL IGNORE TABLE
---------------------------------------------------------------------------------------------------------
OK
 
DDL IGNORE LOG TABLE
---------------------------------------------------------------------------------------------------------
OK
 
DDLAUX  PACKAGE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDLAUX PACKAGE BODY STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
SYS.DDLCTXINFO  PACKAGE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
SYS.DDLCTXINFO  PACKAGE BODY STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDL HISTORY TABLE
---------------------------------------------------------------------------------------------------------
OK
 
DDL HISTORY TABLE(1)
---------------------------------------------------------------------------------------------------------
OK
 
DDL DUMP TABLES
---------------------------------------------------------------------------------------------------------
OK
 
DDL DUMP COLUMNS
---------------------------------------------------------------------------------------------------------
OK
 
DDL DUMP LOG GROUPS
---------------------------------------------------------------------------------------------------------
OK
 
DDL DUMP PARTITIONS
---------------------------------------------------------------------------------------------------------
OK
 
DDL DUMP PRIMARY KEYS
---------------------------------------------------------------------------------------------------------
OK
 
DDL SEQUENCE
---------------------------------------------------------------------------------------------------------
OK
 
GGS_TEMP_COLS
---------------------------------------------------------------------------------------------------------
OK
 
GGS_TEMP_UK
---------------------------------------------------------------------------------------------------------
OK
 
DDL TRIGGER CODE STATUS:
 
Line/pos
------------------------------------------------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
DDL TRIGGER INSTALL STATUS
---------------------------------------------------------------------------------------------------------
OK
 
DDL TRIGGER RUNNING STATUS
------------------------------------------------------------------------------------------------------------------------
ENABLED
 
STAYMETADATA IN TRIGGER
------------------------------------------------------------------------------------------------------------------------
OFF
 
DDL TRIGGER SQL TRACING
------------------------------------------------------------------------------------------------------------------------
0
 
DDL TRIGGER TRACE LEVEL
------------------------------------------------------------------------------------------------------------------------
0
 
LOCATION OF DDL TRACE FILE
------------------------------------------------------------------------------------------------------------------------
/data/oracle/diag/rdbms/rac1/rac1/trace/ggs_ddl_trace.log
 
Analyzing installation status...
 
 
STATUS OF DDL REPLICATION
------------------------------------------------------------------------------------------------------------------------
SUCCESSFUL installation of DDL Replication software components
 
Script complete.
SQL> @role_setup.sql        #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<执行第三个脚本
 
GGS Role setup script
 
This script will drop and recreate the role GGS_GGSUSER_ROLE
To use a different role name, quit this script and then edit the params.sql script to change the gg_role parameter to the preferred name. (Do not run the script.)
 
You will be prompted for the name of a schema for the GoldenGate database objects.
NOTE: The schema must be created prior to running this script.
NOTE: Stop all DDL replication before starting this installation.
 
Enter GoldenGate schema name:ogg
Wrote file role_setup_set.txt
 
PL/SQL procedure successfully completed.
 
 
Role setup script complete
 
Grant this role to each user assigned to the Extract, GGSCI, and Manager processes, by using the following SQL command:
 
GRANT GGS_GGSUSER_ROLE TO <loggedUser>
 
where <loggedUser> is the user assigned to the GoldenGate processes.
SQL> GRANT GGS_GGSUSER_ROLE TO ogg;                 #<<<<<<<<根据上方运行结果输入授权
 
Grant succeeded.
 
SQL> @ddl_enable                                    #<<<<<<<<<<<<<<<<<执行第四个脚本
 
Trigger altered.
 
SQL> @/data/oracle/sit/product/11.2.0.4/db_1/rdbms/admin/dbmspool.sql        #<<<<<<<<<<<<<<<<<执行第五个脚本
 
Package created.
 
 
Grant succeeded.
 
SQL> @ddl_pin.sql ogg                        #<<<<<<<<<<<<<<<<<<<<<执行第六个脚本,后面参数引入用户
 
PL/SQL procedure successfully completed.
 
 
PL/SQL procedure successfully completed.
 
 
PL/SQL procedure successfully completed.
 
SQL> @sequence.sql                               #<<<<<<<<<<<<<<<<<执行第七个脚本
Please enter the name of a schema for the GoldenGate database objects:
ogg
Setting schema name to OGG
 
UPDATE_SEQUENCE STATUS:
 
Line/pos
--------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
GETSEQFLUSH
 
Line/pos
--------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
SEQTRACE
 
Line/pos
--------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
REPLICATE_SEQUENCE STATUS:
 
Line/pos
--------------------------------------------------------------------------------
Error
-----------------------------------------------------------------
No errors
No errors
 
 
STATUS OF SEQUENCE SUPPORT
--------------------------------------------------------------------------------
SUCCESSFUL installation of Oracle Sequence Replication support
 
#至此DDL同步配置完成。

※5、备份机器创建存储用户与表空间信息(如备机有存在则忽略此步骤)

#前言说明:因为表有做分区,同步数据尽量做一模一样的表空间防止分区表数据未能同步过来[oracle@rac2 ogg]$ sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.4.0 Production on Thu Apr 7 01:31:37 2022
 
Copyright (c) 1982, 2013, Oracle. All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> CREATE test TS_LOG datafile '/data/oracle/sit/datafile/test.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE TS_LOG datafile '/data/oracle/sit/datafile/TS_LOG.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE test1 TS_ORDER datafile '/data/oracle/sit/datafile/test1.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE TS_ORDER datafile '/data/oracle/sit/datafile/TS_ORDER.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE test2 TS_ORDER_DETAIL datafile '/data/oracle/sit/datafile/test2.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE TS_ORDER_DETAIL datafile '/data/oracle/sit/datafile/TS_ORDER_DETAIL.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE TABLESPACE test3 datafile '/data/oracle/sit/datafile/test3.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE TS_TRANS datafile '/data/oracle/sit/datafile/TS_TRANS.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE TABLESPACE test4 datafile '/data/oracle/sit/datafile/test4.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE TS_WIN_REC datafile '/data/oracle/sit/datafile/TS_WIN_REC.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE TABLESPACE test5 datafile '/data/oracle/sit/datafile/test5.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE CGSIT2019 datafile '/data/oracle/sit/datafile/CGSIT2019.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE TABLESPACE test6 datafile '/data/oracle/sit/datafile/test6.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE CGSITDB datafile '/data/oracle/sit/datafile/CGSITDB.dbf' SIZE 5G EXTENT MANAGEMENT LOCALGrant succeeded.
 
SQL> CREATE TABLESPACE test7 datafile '/data/oracle/sit/datafile/test7.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE CGSIT2019DB datafile '/data/oracle/sit/datafile/CGSIT2019DB.dbf' SIZE 5G EXTENT MANAGEMENT LOCAL
 
Grant succeeded.
 
SQL> create user wander identified by wander default tablespace test temporary tablespace temp;
 
Grant succeeded.
 
SQL> grant connect,resource to wander;
 
Grant succeeded.

※6、授权确认复制的表或sequence给与ogg用户

#注意事项,源数据端可直接授权,备份端需要手动创建表结构,然后再授权,本地测试的用户wander为表的属主授权给同步备份用户
SQL> grant INSERT, UPDATE, DELETE on wander.FS_S12_test1 to ogg;
 
Grant succeeded.
 
SQL> grant INSERT, UPDATE, DELETE on wander.FS_S12_test2 to ogg;
 
Grant succeeded.
 
SQL> grant INSERT, UPDATE, DELETE on wander.test3 to ogg;
 
Grant succeeded.
 
SQL> grant ALL on wander.SEQ_test to ogg;
 
Grant succeeded.
 
SQL> grant ALL on wander.SEQ_test2 to ogg;
 
Grant succeeded.

※7、配置单项复制(启动时抓取数据推送,只会复制进程启动的时候数据,原本的数据不会抓取,需要手动把源端的数据导入过去)

注意事项:操作ogg命令每次都需要到指定的目录,否者会出现备份错误,找不到路径的情况,工作目录:/data/ogg/

#源机器操作
[oracle@k8scgsitdb ogg]$ cd /data/ogg/
[oracle@k8scgsitdb ogg]$ ./ggsci
 
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21
 
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 
GGSCI (k8scgsitdb) 0> create subdirs                #请在源端与备份机器执行这个创建工作目录命令
 
Creating subdirectories under current directory /data/ogg
 
Parameter files                /data/ogg/dirprm: already exists
Report files                   /data/ogg/dirrpt: created
Checkpoint files               /data/ogg/dirchk: created
Process status files           /data/ogg/dirpcs: created
SQL script files               /data/ogg/dirsql: created
Database definitions files     /data/ogg/dirdef: created
Extract data files             /data/ogg/dirdat: created
Temporary files                /data/ogg/dirtmp: created
Stdout files                   /data/ogg/dirout: created
 
 
GGSCI (k8scgsitdb) 1> dblogin userid ogg, password ogg
Successfully logged into database.
 
 
GGSCI (k8scgsitdb) 2> edit param mgr
#进入vim编辑模式
PORT 7809
DYNAMICPORTLIST  7840-7939
AUTOSTART EXTRACT *
AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 2
PURGEOLDEXTRACTS /data/ogg/dirdat/*, USECHECKPOINTS, MINKEEPDAYS 5
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
---拷贝保存 wq!
 
注:
 
PORT 7839
 
通信端口7839, 源端和目标端需要保持一致。
 
DYNAMICPORTLIST  7840-7939
 
动态端口列表的范围从7840到7939。当制定端口被占用或者出现通信故障,管理进程将会从列表中选择下一个端口尝试连接,避免通信端口的单点故障。
 
AUTOSTART EXTRACT *
 
当MGR进程启动后启动EXTRACT进程
 
AUTORESTART EXTRACT *, RETRIES 5, WAITMINUTES 2
 
当EXTRACT进程中断后尝试自动重启,每隔2分钟尝试启动一次,尝试5次。
 
PURGEOLDEXTRACTS /data/oracle/product/ogg_src/dirdat/*, USECHECKPOINTS, MINKEEPDAYS 5
 
(相对路径写法)PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPDAYS 5
 
定期清理dirdat路径下的本地队列(local trail)。保留期限10天,过期后自动删除。从而控制队列文件的目录不会增长过大。
 
LAGREPORTHOURS 1
 
每隔一小时检查各进程延时情况,并记录到goldengate report文件。
 
LAGINFOMINUTES 30
 
进程复制延时超过30分钟,向日志文件记录一条错误日志
 
LAGCRITICALMINUTES 45
 
传输延时超过45分钟将写入警告日志
 
 
 
#################################################################################################################
#目标备份机器操作
[oracle@wander ogg]$ cd /data/ogg/ && ./ggsci
 
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21
 
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 
 
 
GGSCI (wander) 1> edit param mgr
PORT 7809
USERID ogg, PASSWORD ogg
DYNAMICPORTLIST  7840-7939
AUTOSTART REPLICAT *
AUTORESTART REPLICAT *, RETRIES 5, WAITMINUTES 2
PURGEOLDEXTRACTS /data/ogg/dirdat/*, USECHECKPOINTS, MINKEEPDAYS 5
PURGEDDLHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
PURGEMARKERHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
LAGREPORTHOURS 1
LAGINFOMINUTES 30
LAGCRITICALMINUTES 45
 
注:
 
USERID ogg, PASSWORD pwd
 
GoldenGate用户登录数据库的用户名和密码,密码未做加密处理。
 
如果密码需要加密使用:GGSCI (dbtrg) 1> encrypt password pwd ,ENCRYPTKEY default
 
可以得到加密后的密码字符串,之后配置进程若使用加密过的密码,需要带参数(ENCRYPTKEY default)。
 
例如:USERID ogg, PASSWORD xxx(加密过的密码) ,ENCRYPTKEY default
 
AUTOSTART REPLICAT *
 
当MGR进程启动后启动REPLICAT进程
 
AUTORESTART REPLICAT *, RETRIES 5, WAITMINUTES 2
 
当REPLICAT进程中断后尝试自动重启,每隔2分钟尝试启动一次,尝试5次。
 
PURGEDDLHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
 
删除DDL历史表,最小保存7天,最大保存10天。
 
PURGEMARKERHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10
 
删除MARKER历史表,最小保存7天,最大保存10天。
 
##源DB端配置,还是ggsci命令操作
GGSCI (k8scgsitdb) 1> dblogin userid ogg, password ogg
Successfully logged into database.
 
GGSCI (k8scgsitdb) 2> add extract k8s1,tranlog,begin now
ERROR: EXTRACT K8S1 already exists.      #演示部分,显示已存在,正常显示创建成功
 
GGSCI (k8scgsitdb) 3> add exttrail /data/ogg/dirdat/sr, extract k8s1
ERROR: EXTRACT K8S1 already exists.      #演示部分,显示已存在,正常显示创建成功
 
GGSCI (k8scgsitdb) 4> edit param k8s1
#进入vim编辑模式
extract k8s1
SETENV(ORACLE_SID="rac1")
SETENV(NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg, password ogg
REPORTCOUNT EVERY 30 MINUTES, RATE
DISCARDFILE /data/ogg/dirrpt/extsr.dsc, APPEND, MEGABYTES 1024
DISCARDROLLOVER AT 3:00
EXTTRAIL /data/ogg/dirdat/sr
DYNAMICRESOLUTION
DBOPTIONS  ALLOWUNUSEDCOLUMN
FETCHOPTIONS NOUSESNAPSHOT
FETCHOPTIONS FETCHPKUPDATECOLS
DDL  INCLUDE  ALL
DDLOPTIONS  ADDTRANDATA
table wander.test;
---保存
注:
SETENV(ORACLE_SID="orcl")
设置Oracle数据库实例sid
SETENV(NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
设置goldengate的字符集变量信息,此处值会覆盖操作系统级别的变量。该值需要和数据库字符集匹配一致。
REPORTCOUNT EVERY 30 MINUTES, RATE
每隔30分钟报告一次从程序开始到现在的抽取进程或者复制进程的事物记录数,并汇报进程的统计信息
DISCARDFILE /data/oracle/product/ogg_src/dirrpt/extsr.dsc, APPEND, MEGABYTES 1024
将执行失败的记录保存在discard file中,discard file文件记录了GoldenGate进程错误、数据库错误、GoldenGate操作等信息。该文件位于/data/oracle/product/ogg_src/dirrpt/extsr.dsc,大小为1024MB。 文件中已经包含记录的话,再后面继续追加,不删除之前的记录。
DISCARDROLLOVER AT 3:00
为了防止discard file被写满,每天3:00做一次文件过期设定
EXTTRAIL /data/oracle/product/ogg_src/dirdat/sr
队列文件路径, trail文件存放路径。
DYNAMICRESOLUTION
有时候开启OGG进程的时候较慢,可能是因为需要同步的表太多,OGG在开启进程之前会将需要同步的表建立一个记录并且存入到磁盘中,这样就需要耗费大量的时间。使用该参数来解决此问题。
DBOPTIONS  ALLOWUNUSEDCOLUMN
用于阻止抽取进程抽取数据时由于表含有unused列而导致进程异常终止(abend)。使用该参数,抽取进程抽取到unused列时也会向日志文件记录一条警告信息。
FETCHOPTIONS NOUSESNAPSHOT
默认值为 usesnapshot,表示利用数据库闪回读取数据。Nousesnapshot表示直接从原表读取相关数据。
FETCHOPTIONS FETCHPKUPDATECOLS
当使用了HANDLECOLLISIONS时,请使用该参数。
复制进程出现丢失update记录(missing update)并且更新的是主键,update将转换成insert。由于插入的记录可能不是完整的行,若要保证完整需要加入此参数
table ogg.*;
需要复制的对象列表
##创建并指定源数据库trail文件位置,必须包含两个字符,这个路径和主抽取进程(Primary Extract)中指定的trail目录和trail文件命名必须相同,因为Data Pump进程要从此读取主抽取进程生成的trail文件;
GGSCI (k8scgsitdb) 5> add extract dpump1, exttrailsource /data/ogg/dirdat/sr
 
GGSCI (k8scgsitdb) 7> edit param dpump1
#进入vim编辑模式
extract dpump1
SETENV(ORACLE_SID="rac1")
SETENV(NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
RMTHOST 192.168.167.111, mgrport 7809, COMPRESS
PASSTHRU
RMTTRAIL /data/ogg/dirdat/tr
table wander.FS_S12_test;
---保存
 
注:
RMTHOST 192.168.167.111, mgrport 7809, COMPRESS
目标端主机IP,管理进程端口号,投递前压缩队列文件
PASSTHRU
表示传输进程直接跟抽取进程交互,而不再和数据库进行交互,减少数据库资源的利用。
RMTTRAIL /data/oracle/product/ogg_trg/dirdat/tr
目标端保存队列文件的目录
DYNAMICRESOLUTION
动态解析表名
table ogg.*;
复制范围和抽取进程对应即可
源端可以配置多个主抽取进程,也可以配置多个Data Pump进程,但必须为每个要同步的目标端配置一个Data Pump进程;
 
 
 
##指定Data Pump进程发送trail文件到目标端的位置(目标端trail文件添加到队列中)
GGSCI (k8scgsitdb) 8> add rmttrail /data/ogg/dirdat/tr, extract dpump1
ERROR: EXTRACT K8S1 already exists.      #演示部分,显示已存在,正常显示创建成功
 
 
GGSCI (k8scgsitdb) 9> add  trandata wander.FS_S12test     #<<<<<<<<<<<<<<<注意这边需要单独开启表的DML,否则不会同步信息,有几张表就运行几次
 
#配置备机进程
[oracle@wander ogg]$ cd /data/ogg/ && ./ggsci
 
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21
 
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 
 
 
GGSCI (wander) 1> dblogin userid ogg, password ogg
Successfully logged into database.
 
GGSCI (wander) 2> add checkpointtable ogg.checkpoint
 
GGSCI (wander) 3> edit param ./GLOBALS
#进入vim编辑模式复制下面内容粘贴
GGSCHEMA ogg
CHECKPOINTTABLE ogg.checkpoint
---
GGSCI (wander) 4> add replicat rep1, exttrail /data/ogg/dirdat/tr, checkpointtable ogg.checkpoint
 
GGSCI (wander) 5> edit param rep1
#进入vim编辑模式
REPLICAT rep1
SETENV(ORACLE_SID="rac2")
SETENV(NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID ogg, PASSWORD ogg
REPORT AT 06:00
REPORTCOUNT EVERY 30 MINUTES, RATE
REPORTROLLOVER AT 02:00
REPERROR DEFAULT, ABEND
ALLOWNOOPUPDATES
ASSUMETARGETDEFS
HANDLECOLLISIONS
DISCARDFILE /data/ogg/dirrpt/repsa.dsc, APPEND, MEGABYTES 1024
DDLERROR  DEFAULT  IGNORE
MAP wander.*, target wander.*;
---
注:
REPORT AT 06:00
每天06:00定期生成一个report文件
REPORTCOUNT EVERY 30 MINUTES, RATE
每隔30分钟报告一次从程序开始到现在的抽取进程或者复制进程的事物记录数,并汇报进程的统计信息
REPORTROLLOVER AT 02:00
为了防止report file被写满,每天2:00做一次文件过期设定
REPERROR DEFAULT, ABEND
除了特殊指定的REPERROR语句,报告所有复制期间出现的错误,回滚非正常中断的事物和进程。遇到不能处理的错误就自动abend,启动需要人工干预处理
ALLOWNOOPUPDATES
当源表有排除列情况或者有目标表不存在的列时,当更新这列goldengate默认报错。应用该参数后,即可让goldengate生成一条警告信息而不是报错。
ASSUMETARGETDEFS
使用ASSUMETARGETDEFS参数时,用MAP语句中指定的生产库源表和灾备端目标表具有相同的列结构。它指示的Oracle GoldenGate不在生产端查找源表的结构定义。
HANDLECOLLISIONS
用于goldengate自动过滤不能出来的冲突记录,为了严格保证数据一致性
DISCARDFILE /data/oracle/product/ogg_trg/dirrpt/repsa.dsc, APPEND, MEGABYTES 1024
将执行失败的记录保存在discard file中,discard file文件记录了GoldenGate进程错误、数据库错误、GoldenGate操作等信息。该文件位于./dirrpt/repsa.dsc,大小为1024MB。 文件中已经包含记录的话,再后面继续追加,不删除之前的记录。
DISCARDROLLOVER AT 02:00
为了防止discard file被写满,每天2:00做一次文件过期设定
MAP wander.*, target wander.*;
对应需要复制的对象,默认一一对应传输进程

※9、指定数据表导入导出

导出:
expdp wander/wander directory=wander_dir  dumpfile=1.dump tables=FS_S12_PTG0125_ROTATE_VALUE,FS_S12_FISHING_TRANS_125,FS_S12_PLAYER
导入
impdp wander/wander dumpfile=1.dump directory=wander_imp table_exists_action=replace

※10、启动进程(源DB机器与备份端均有操作,请注意看注释会说明哪台机器操作)

#源DB机器启动
[oracle@k8scgsitdb ogg]$ cd /data/ogg/ && ./ggsci
 
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21
 
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 
 
 
GGSCI (k8scgsitdb) 1> start mgr
Manager started.
 
 
#备份机器操作
[oracle@wander ogg]$ cd /data/ogg/ && ./ggsci
 
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21
 
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
 
 
 
GGSCI (wander) 1>start mgr
Manager started.

剩余的即可在源端所设置的表进行增删改查测试同步情况


Comment