1. 环境说明:
ORACLE 版本:10.2.0.1 RAC
裸设备无ASM
2. GG安装目录必须是共享磁盘。
格式化共享磁盘挂载于第一节点。
3. 在源端建立GOLDENGATE用户。
源端:
SQL> create user goldengate identified by goldengate default tablespace goldengate;
User created.
SQL> grant dba to goldengate;
Grant succeeded.
目标端:
SQL> create user goldengate identified by goldengate default tablespace goldengate;
User created.
SQL> grant dba to goldengate;
Grant succeeded.
4. 创建GOLDENGATE所需目录。
源端:
[oracle@rac1 ggsource]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
Linux, x64, 64bit (optimized), Oracle 10g on Oct 4 2011 23:50:20
Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
GGSCI (rac1) 1> create subdirs
Creating subdirectories under current directory /gg/ggsource
Parameter files /gg/ggsource/dirprm: created
Report files /gg/ggsource/dirrpt: created
Checkpoint files /gg/ggsource/dirchk: created
Process status files /gg/ggsource/dirpcs: created
SQL script files /gg/ggsource/dirsql: created
Database definitions files /gg/ggsource/dirdef: created
Extract data files /gg/ggsource/dirdat: created
Temporary files /gg/ggsource/dirtmp: created
Veridata files /gg/ggsource/dirver: created
Veridata Lock files /gg/ggsource/dirver/lock: created
Veridata Out-Of-Sync files /gg/ggsource/dirver/oos: created
Veridata Out-Of-Sync XML files /gg/ggsource/dirver/oosxml: created
Veridata Parameter files /gg/ggsource/dirver/params: created
Veridata Report files /gg/ggsource/dirver/report: created
Veridata Status files /gg/ggsource/dirver/status: created
Veridata Trace files /gg/ggsource/dirver/trace: created
Stdout files /gg/ggsource/dirout: created
GGSCI (rac1) 2> exit
[oracle@rac1 ggsource]$ mkdir trails
目标端:
[oracle@rac1 ggtarget]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
Linux, x64, 64bit (optimized), Oracle 10g on Oct 4 2011 23:50:20
Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
GGSCI (rac1) 1> create subdirs
Creating subdirectories under current directory /gg/ggtarget
Parameter files /gg/ggtarget/dirprm: created
Report files /gg/ggtarget/dirrpt: created
Checkpoint files /gg/ggtarget/dirchk: created
Process status files /gg/ggtarget/dirpcs: created
SQL script files /gg/ggtarget/dirsql: created
Database definitions files /gg/ggtarget/dirdef: created
Extract data files /gg/ggtarget/dirdat: created
Temporary files /gg/ggtarget/dirtmp: created
Veridata files /gg/ggtarget/dirver: created
Veridata Lock files /gg/ggtarget/dirver/lock: created
Veridata Out-Of-Sync files /gg/ggtarget/dirver/oos: created
Veridata Out-Of-Sync XML files /gg/ggtarget/dirver/oosxml: created
Veridata Parameter files /gg/ggtarget/dirver/params: created
Veridata Report files /gg/ggtarget/dirver/report: created
Veridata Status files /gg/ggtarget/dirver/status: created
Veridata Trace files /gg/ggtarget/dirver/trace: created
Stdout files /gg/ggtarget/dirout: created
GGSCI (rac1) 2> exit
[oracle@rac1 ggtarget]$ mkdir trails
5. 确认源库处于归档模式。
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archivelog
Oldest online log sequence 3
Next log sequence to archive 5
Current log sequence 5
6. 确认源库为FORCE_LOGGIN。
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FOR
---
YES
7. 确认源库打开辅助日志。
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
8. 源库关闭回收站。
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string on
SQL> alter system set recyclebin=off;
System altered.
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string OFF
9. 保证字符集一致。
10. UNDO设置
SQL> alter system set undo_retention=86400;
System altered.
11. 安装DDL_OBJETS
SQL> @marker_setup
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:goldengate
Marker setup table script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to GOLDENGATE
MARKER TABLE
-------------------------------
OK
MARKER SEQUENCE
-------------------------------
OK
Script complete.
执行DDL_STEP
SQL> @ddl_setup
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:goldengate
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 GOLDENGATE as a Oracle GoldenGate schema name.
Working, please wait ...
RECYCLEBIN must be empty.
This installation will purge RECYCLEBIN for all users.
To proceed, enter yes. To stop installation, enter no.
Enter yes or no:yes
DDL replication setup script complete, running verification script...
Please enter the name of a schema for the GoldenGate database objects:
Setting schema name to GOLDENGATE
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
------------------------------------------------------------------------------------------------------------------------
/home/oracle/admin/gg1/udump/ggs_ddl_trace.log
Analyzing installation status...
STATUS OF DDL REPLICATION
------------------------------------------------------------------------------------------------------------------------
SUCCESSFUL installation of DDL Replication software components
Script complete.
执行ROLE_SETUP
SQL> @role_setup
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:goldengate
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.
将此角色给GOLDENGATE用户。
SQL> grant ggs_ggsuser_role to goldengate;
Grant succeeded.
开启DDL
SQL> @ddl_enable
Trigger altered.
安装性能优化包。
SQL> @?/rdbms/admin/dbmspool
Package created.
Grant succeeded.
View created.
Package body created.
ddl_pin将触发器用到的plsql包放进内存中
SQL> @ddl_pin goldengate
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
12. ./GLOBALS配置
源端:
GGSCI (rac1) 1> edit params ./GLOBALS
GGSCHEMA goldengate
目标端:
GGSCI (rac1) 1> edit params ./GLOBALS
GGSCHEMA goldengate
CHECKPOINTTABLE goldengate.chkpoint
GGSCI (rac1) 2> dblogin userid goldengate, password goldengate
Successfully logged into database.
GGSCI (rac1) 3> add checkpointtable goldengate.chkpoint
Successfully created checkpoint table GOLDENGATE.CHKPOINT.
13. MGR配置
源端:
GGSCI (rac1) 2> edit params mgr
DYNAMICPORTLIST 7840-7914
PORT 5898
USERID goldengate@ninvoice1, PASSWORD goldengate
PURGEOLDEXTRACTS /gg/ggsource/trails/w1*, USECHECKPOINTS, MINKEEPFILES 10
AUTORESTART ER *, RETRIES 3, WAITMINUTES 5
PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
目标端:
GGSCI (rac1) 2> edit params mgr
DYNAMICPORTLIST 7915-7989
PORT 5899
USERID goldengate@nimng1, PASSWORD goldengate
PURGEOLDEXTRACTS /gg/ggtarget/trails/w1*, USECHECKPOINTS, MINKEEPFILES 10
AUTORESTART ER *, RETRIES 3, WAITMINUTES 5
14. 源端添加EXTRACT
GGSCI (rac1) 2> add extract w1ext, tranlog, threads 2, begin now
EXTRACT added.
修改配置参数:
GGSCI (rac1) 3> edit params w1ext
EXTRACT w1ext
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID goldengate@ninvoice1, PASSWORD goldengate
EXTTRAIL /gg/ggsource/trails/w1
tranlogoptions rawdeviceoffset 0
DISCARDFILE w1extdsc,APPEND,MEGABYTES 5
TRANLOGOPTIONS ALTARCHIVELOGDEST /oracle/archivelog
TRANLOGOPTIONS ALTARCHIVEDLOGFORMAT %t_%s_%r.dbf
DDL INCLUDE MAPPED
DDLOPTIONS ADDTRANDATA
FETCHOPTIONS, USESNAPSHOT, NOUSELATESTVERSION, MISSINGROW REPORT
STATOPTIONS REPORTFETCH
WARNLONGTRANS 1H, CHECKINTERVAL 5M
TABLE hr.*;
添加该extract对应的trail文件,用来存储抽取的数据。单个文件大小设置为100MB
GGSCI (rac1) 7> add exttrail /gg/ggsource/trails/w1,extract w1ext, MEGABYTES 100
EXTTRAIL added.
15. 源端增加PUMP
GGSCI (rac1) 5> add extract w1extdp, exttrailsource /gg/ggsource/trails/w1, begin now
EXTRACT added.
修改配置:
GGSCI (rac1) 6> edit params w1extdp
EXTRACT w1extdp
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID goldengate@ninvoice1, PASSWORD goldengate
RMTHOST rac1, MGRPORT 5899
RMTTRAIL /gg/ggtarget/trails/w1
DISCARDFILE w1extdpdsc,APPEND,MEGABYTES 5
TABLE hr.*;
增加RMTRAIL:
GGSCI (rac1) 7> add rmttrail /gg/ggtarget/trails/w1, extract w1extdp, megabytes 100
RMTTRAIL added.
16. 增加目标端REP
GGSCI (rac1) 3> add replicat w1rep, exttrail /gg/ggtarget/trails/w1, checkpointtable goldengate.chkpoint
REPLICAT added.
修改配置:
GGSCI (rac1) 4> edit params w1rep
REPLICAT w1rep
ASSUMETARGETDEFS
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID goldengate@nimng1, PASSWORD goldengate
DISCARDFILE w1repdsc,APPEND,MEGABYTES 5
DDL INCLUDE MAPPED
DDLOPTIONS REPORT
BATCHSQL
DBOPTIONS DEFERREFCONST
DBOPTIONS LOBWRITESIZE 102400
HANDLECOLLISIONS
DDLERROR DEFAULT DISCARD RETRYOP MAXRETRIES 5 RETRYDELAY 20
tableexclude hr.mv*
MAP hr.* , TARGET hr.* ;
17. 源端增加传输表。
GGSCI (rac1) 8> dblogin userid goldengate, password goldengate
Successfully logged into database.
GGSCI (rac1) 9> add trandata hr.*
Logging of supplemental redo log data is already enabled for table HR.COUNTRIES.
Logging of supplemental redo log data is already enabled for table HR.DEPARTMENTS.
Logging of supplemental redo log data is already enabled for table HR.EMPLOYEES.
Logging of supplemental redo log data is already enabled for table HR.JOBS.
Logging of supplemental redo log data is already enabled for table HR.JOB_HISTORY.
Logging of supplemental redo log data is already enabled for table HR.LOCATIONS.
2012-09-21 16:21:46 WARNING OGG-00869 No unique key is defined for table MLOG$_MV_T21. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo data enabled for table HR.MLOG$_MV_T21.
Logging of supplemental redo data enabled for table HR.MV_T21.
Logging of supplemental redo log data is already enabled for table HR.REGIONS.
2012-09-21 16:21:47 WARNING OGG-00869 No unique key is defined for table T. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T.
2012-09-21 16:21:47 WARNING OGG-00869 No unique key is defined for table T1. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T1.
2012-09-21 16:21:47 WARNING OGG-00869 No unique key is defined for table T2. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T2.
Logging of supplemental redo log data is already enabled for table HR.T21.
2012-09-21 16:21:48 WARNING OGG-00869 No unique key is defined for table T22. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T22.
2012-09-21 16:21:48 WARNING OGG-00869 No unique key is defined for table T228. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T228.
2012-09-21 16:21:48 WARNING OGG-00869 No unique key is defined for table T23. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T23.
2012-09-21 16:21:48 WARNING OGG-00869 No unique key is defined for table T25. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo data enabled for table HR.T25.
2012-09-21 16:21:49 WARNING OGG-00869 No unique key is defined for table T28. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T28.
2012-09-21 16:21:49 WARNING OGG-00869 No unique key is defined for table T288. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T288.
2012-09-21 16:21:49 WARNING OGG-00869 No unique key is defined for table T33. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T33.
2012-09-21 16:21:49 WARNING OGG-00869 No unique key is defined for table T88. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.T88.
2012-09-21 16:21:50 WARNING OGG-00869 No unique key is defined for table TEST28. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo log data is already enabled for table HR.TEST28.
18. 初始化数据。
查询SCN
导出数据:
[oracle@rac1 ~]$ exp hr/hr@ninvoice1 owner=hr flashback_scn=2748147 file=hr.dmp log=log.log
Export: Release 10.2.0.1.0 - Production on Fri Sep 21 16:28:41 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user HR
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user HR
About to export HR's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export HR's tables via Conventional Path ...
. . exporting table COUNTRIES 25 rows exported
. . exporting table DEPARTMENTS 27 rows exported
. . exporting table EMPLOYEES 107 rows exported
. . exporting table JOBS 19 rows exported
. . exporting table JOB_HISTORY 10 rows exported
. . exporting table LOCATIONS 23 rows exported
. . exporting table MLOG$_MV_T21 0 rows exported
. . exporting table MV_T21 1 rows exported
. . exporting table REGIONS 4 rows exported
. . exporting table T 107 rows exported
. . exporting table T1 11 rows exported
. . exporting table T2 0 rows exported
. . exporting table T21 3 rows exported
. . exporting table T22 11 rows exported
. . exporting table T228 11 rows exported
. . exporting table T23 13 rows exported
. . exporting table T25 3 rows exported
. . exporting table T28 1 rows exported
. . exporting table T288 1 rows exported
. . exporting table T33 11 rows exported
. . exporting table T88 2 rows exported
. . exporting table TEST28 1 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
导入目标库
[oracle@rac1 ~]$ imp hr/hr@nimng1 fromuser=hr touser=hr file=hr.dmp ignore=y log=log.log
Import: Release 10.2.0.1.0 - Production on Fri Sep 21 16:31:04 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. . importing table "COUNTRIES" 25 rows imported
. . importing table "DEPARTMENTS" 27 rows imported
. . importing table "EMPLOYEES" 107 rows imported
. . importing table "JOBS" 19 rows imported
. . importing table "JOB_HISTORY" 10 rows imported
. . importing table "LOCATIONS" 23 rows imported
. . importing table "MLOG$_MV_T21" 0 rows imported
. . importing table "MV_T21" 1 rows imported
. . importing table "REGIONS" 4 rows imported
. . importing table "T" 107 rows imported
. . importing table "T1" 11 rows imported
. . importing table "T2" 0 rows imported
. . importing table "T21" 3 rows imported
. . importing table "T22" 11 rows imported
. . importing table "T228" 11 rows imported
. . importing table "T23" 13 rows imported
. . importing table "T25" 3 rows imported
. . importing table "T28" 1 rows imported
. . importing table "T288" 1 rows imported
. . importing table "T33" 11 rows imported
. . importing table "T88" 2 rows imported
19. 启动GG进程。注意启REP时按SCN启动。
20. 测试
源库:
[oracle@rac1 ggsource]$ sqlplus hr/hr@ninvoice1
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Sep 21 16:48:38 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
SQL> create table ttt(id number(9));
Table created.
SQL> insert into ttt(id) values(888);
1 row created.
SQL> commit;
Commit complete.
目标库:
SQL> select * from ttt;
ID
----------
888
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
nimng1