ORACLE GOLDENGATE DDL单向同步

1. 环境介绍
ORACLE版本: 10.2.0.1
GG版本: 11.2.1

2.解压安装包。
3.配置环境变量。
源端:增加如下配置

export GG_HOME=/home/oracle/gg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GG_HOME:/usr/lib


目标端:增加如下配置

export GG_HOME=/home/oracle/gg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GG_HOME:/usr/lib


3. 创建目录
源端:

[oracle@GOLDENGATE1 gg]$ ./ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x86, 32bit (optimized), Oracle 10g on Apr 23 2012 07:06:02

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.

 

GGSCI (GOLDENGATE1) 1> create subdirs

Creating subdirectories under current directory /home/oracle/gg

Parameter files                /home/oracle/gg/dirprm: already exists
Report files                   /home/oracle/gg/dirrpt: created
Checkpoint files               /home/oracle/gg/dirchk: created
Process status files           /home/oracle/gg/dirpcs: created
SQL script files               /home/oracle/gg/dirsql: created
Database definitions files     /home/oracle/gg/dirdef: created
Extract data files             /home/oracle/gg/dirdat: created
Temporary files                /home/oracle/gg/dirtmp: created
Stdout files                   /home/oracle/gg/dirout: created


GGSCI (GOLDENGATE1) 2> exit
[oracle@GOLDENGATE1 gg]$ mkdir trails


目标端:

[oracle@GOLDENGATE2 gg]$ ./ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
Linux, x86, 32bit (optimized), Oracle 10g on Apr 23 2012 07:06:02

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.

 

GGSCI (GOLDENGATE2) 1> create subdirs

Creating subdirectories under current directory /home/oracle/gg

Parameter files                /home/oracle/gg/dirprm: already exists
Report files                   /home/oracle/gg/dirrpt: created
Checkpoint files               /home/oracle/gg/dirchk: created
Process status files           /home/oracle/gg/dirpcs: created
SQL script files               /home/oracle/gg/dirsql: created
Database definitions files     /home/oracle/gg/dirdef: created
Extract data files             /home/oracle/gg/dirdat: created
Temporary files                /home/oracle/gg/dirtmp: created
Stdout files                   /home/oracle/gg/dirout: created


GGSCI (GOLDENGATE2) 2> exit
[oracle@GOLDENGATE2 gg]$ mkdir trails


4.创建GOLDENGATE用户
源端:

SQL> create tablespace goldengate datafile'/home/oracle/oradata/gg1/gg01.dbf' size 500m;

Tablespace created.

SQL> create user goldengate identified by goldengate default tablespace goldengate;

User created.

SQL> grant dba to goldengate;

Grant succeeded.


目标端:

SQL>  create tablespace goldengate datafile'/home/oracle/oradata/gg1/gg01.dbf' size 500m;

Tablespace created.

SQL> create user goldengate identified by goldengate default tablespace goldengate;

User created.

SQL> grant dba to goldengate;

Grant succeeded.


5. 确认源库处于归档模式。

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /home/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. 配置MGR
源端:

GGSCI (GOLDENGATE1) 1> edit params mgr
DYNAMICPORTLIST 7840-7914
PORT 5898
PURGEOLDEXTRACTS /home/oracle/gg/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 (GOLDENGATE1) 1> edit params mgr
DYNAMICPORTLIST 7840-7914
PORT 5898
PURGEOLDEXTRACTS /home/oracle/gg/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


13. 配置./GLOBALS
源端:

GGSCI (GOLDENGATE1) 2> edit params ./GLOBALS
GGSCHEMA goldengate


目标端:

GGSCI (GOLDENGATE2) 3> dblogin userid goldengate, password goldengate
Successfully logged into database.

GGSCI (GOLDENGATE2) 5> add checkpointtable goldengate.chkpoint

Successfully created checkpoint table goldengate.chkpoint.

GGSCI (GOLDENGATE2) 6> edit params ./GLOBALS
GGSCHEMA goldengate
CHECKPOINTTABLE goldengate.chkpoint


14. 增加EXTRAIL

GGSCI (GOLDENGATE1) 3> add extract w1ext, tranlog, begin now
EXTRACT added.

修改EXTRAIL参数
GGSCI (GOLDENGATE1) 4> edit params w1ext
EXTRACT w1ext
USERID goldengate, PASSWORD goldengate
EXTTRAIL /home/oracle/gg/trails/w1
DISCARDFILE w1extdsc,APPEND,MEGABYTES 5
TRANLOGOPTIONS ALTARCHIVELOGDEST /home/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 (GOLDENGATE1) 5> add exttrail /home/oracle/gg/trails/w1, extract w1ext, megabytes 100
EXTTRAIL added.


15 增加PUMP

add extract w1extdp, exttrailsource /home/oracle/gg/trails/w1, begin now
EXTRACT added.


修改PUMP参数

GGSCI (GOLDENGATE1) 7> edit params w1extdp
EXTRACT w1extdp
USERID goldengate, PASSWORD goldengate
RMTHOST 192.168.102.157, MGRPORT 5898
RMTTRAIL /home/oracle/gg/trails/w1
DISCARDFILE w1extdpdsc,APPEND,MEGABYTES 5
TABLE hr.*;


添加RMTRAILS

GGSCI (GOLDENGATE1) 9> add rmttrail /home/oracle/gg/trails/w1, extract w1extdp, megabytes 100
RMTTRAIL added.


16. 增加目标端REP

GGSCI (GOLDENGATE2) 8> add replicat w1rep, exttrail /home/oracle/gg/trails/w1, checkpointtable goldengate.chkpoint
REPLICAT added.


修改REP参数

GGSCI (GOLDENGATE2) 9> edit params w1rep
REPLICAT w1rep
ASSUMETARGETDEFS
USERID goldengate, PASSWORD goldengate
DISCARDFILE w1repdsc,APPEND,MEGABYTES 5
DDL INCLUDE MAPPED
DDLOPTIONS REPORT
BATCHSQL
DBOPTIONS DEFERREFCONST
DBOPTIONS LOBWRITESIZE 102400
DDLERROR DEFAULT DISCARD RETRYOP MAXRETRIES 5 RETRYDELAY 20
MAP hr.* , TARGET hr.* ;


17. 在源端增加传输表。

GGSCI (GOLDENGATE1) 10> dblogin userid goldengate, password goldengate
Successfully logged into database.

GGSCI (GOLDENGATE1) 11> 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.

Logging of supplemental redo log data is already enabled for table HR.REGIONS.

2012-09-21 00:27:22  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.


18. 初始化数据到目标库
查询源库SCN

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     526047


导出数据。

[oracle@GOLDENGATE1 ~]$ exp hr/hr owner=hr file=hr.dmp flashback_scn=526047 log=log.log

Export: Release 10.2.0.1.0 - Production on Fri Sep 21 00:29:24 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in AL32UTF8 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                        REGIONS          4 rows exported
. . exporting table                              T          2 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@GOLDENGATE2 ~]$ imp hr/hr fromuser=hr touser=hr file=hr.dmp ignore=y log=log.log

Import: Release 10.2.0.1.0 - Production on Fri Sep 21 02:36:05 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
. . 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                      "REGIONS"          4 rows imported
. . importing table                            "T"          2 rows imported
About to enable constraints...
Import terminated successfully without warnings.


19. 启动GG相关进程, 先两端的MGR,然后源端的EXT进程,然后再目标端的REP进程。
源端:

GGSCI (GOLDENGATE1) 1> start mgr

Manager started.


GGSCI (GOLDENGATE1) 2> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     STOPPED     W1EXT       00:00:00      00:12:53    
EXTRACT     STOPPED     W1EXTDP     00:00:00      00:10:15    


GGSCI (GOLDENGATE1) 3> start *

Sending START request to MANAGER ...
EXTRACT W1EXT starting

Sending START request to MANAGER ...
EXTRACT W1EXTDP starting


GGSCI (GOLDENGATE1) 4> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     RUNNING     W1EXT       00:00:00      00:13:34    
EXTRACT     RUNNING     W1EXTDP     00:00:00      00:10:55    

目标端:
GGSCI (GOLDENGATE2) 9> start mgr

Manager started.


GGSCI (GOLDENGATE2) 10> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    STOPPED     W1REP       00:00:00      00:06:20    


GGSCI (GOLDENGATE2) 11> start w1rep, aftercsn 526047

Sending START request to MANAGER ...
REPLICAT W1REP starting


GGSCI (GOLDENGATE2) 12> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    RUNNING     W1REP       00:00:00      00:00:00    


20, 数据测试
源端:

SQL> create table tt(id number(9));

Table created.

SQL> insert into tt(id) values(88);

1 row created.

SQL> commit;

Commit complete.

目标端:
SQL> select * from tt;

        ID
----------
        88


 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值