11gR2 Ora2Ora 单向复制 GG

来源:互联网 发布:部落冲突刷钻石软件 编辑:程序博客网 时间:2024/04/20 22:15

    原文地址 http://blog.csdn.net/tianlesoftware/article/details/6950018

 

 

 

在前面几篇了看了GG 的安装配置的一些理论东西,在这篇来搭建一个Oracle 到Oracle 的一个Golden Gate 测试环境。

 

测试环境:

OS: Redhat 5.4 64bit

DB: Oracle 11.2.0.3 64bit

 

相关的理论知识参考:

Oracle Golden Gate 系列四 --GG 安装 与 卸载 理论知识

http://blog.csdn.net/tianlesoftware/article/details/6937183

 

示例采用GoldenGate典型的配置:

在Source端,配置一个管理进程, 添加一个Extract进程,添加一个本地队列路径,定义一个远端的接收队列路径。
在Target端,配置一个管理进程和添加一个Replicat进程,指定一个应用队列,即抽取进程定义的远端队列。


一.安装GG 软件

1.1 OS 和 DB 版本

[root@gg2 ~]# uname -a

Linux gg2 2.6.18-164.el5xen #1 SMP Tue Aug18 15:59:52 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

[root@gg2 ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 5.4(Tikanga)

 

SQL> select * from v$version whererownum=1;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise EditionRelease 11.2.0.3.0 - 64bit Production

 

1.2 安装GG

在source database 和 target database 都执行如下操作:

[root@gg2 ~]# su - oracle

gg2:/home/oracle> mkdir /u01/ggate

gg2:/home/oracle> cd /u01

gg2:/u01> ls

app                                 ggate

fbo_ggs_Linux_x64_ora11g_64bit.tar  OGG_WinUnix_Rel_Notes_11.1.1.1.0.pdf

fbo_ggs_Linux_x64_ora11g_64bit.zip  README.txt

gg2:/u01> tar xvffbo_ggs_Linux_x64_ora11g_64bit.tar -C /u01/ggate

 

1.3 添加环境变量

在/home/oracle/.bash_profile文件里添加如下内容:

export PATH=/u01/ggate:$PATH

exportLD_LIBRARY_PATH=/u01/ggate:$LD_LIBRARY_PATH

export GGATE=/u01/ggate

 

注意我这里的GG 和Oracle 使用的是相同的用户,所以把GG 的变量加上就可以了。加载刚刚设置的环境变量:

gg2:/home/oracle> source/home/oracle/.bash_profile

 

1.4 使用ggsci工具,创建必要的目录

gg1:/u01/ggate> ggsci

--调用ggsci 工具

Oracle GoldenGate Command Interpreter forOracle

Version 11.1.1.1OGGCORE_11.1.1_PLATFORMS_110421.2040

Linux, x64, 64bit (optimized), Oracle 11gon Apr 21 2011 22:42:14

 

Copyright (C) 1995, 2011, Oracle and/or itsaffiliates. All rights reserved.

 

GGSCI (gg1) 1> create subdirs

--使用ggsci 工具创建目录

Creating subdirectories under currentdirectory /u01/ggate

 

Parameter files                /u01/ggate/dirprm: created

Report files                   /u01/ggate/dirrpt: created

Checkpoint files               /u01/ggate/dirchk: created

Process status files           /u01/ggate/dirpcs: created

SQL script files               /u01/ggate/dirsql: created

Database definitions files     /u01/ggate/dirdef: created

Extract data files             /u01/ggate/dirdat: created

Temporary files                /u01/ggate/dirtmp: created

Veridata files                 /u01/ggate/dirver: created

Veridata Lock files            /u01/ggate/dirver/lock: created

Veridata Out-Of-Sync files     /u01/ggate/dirver/oos: created

Veridata Out-Of-Sync XML files/u01/ggate/dirver/oosxml: created

Veridata Parameter files       /u01/ggate/dirver/params: created

Veridata Report files          /u01/ggate/dirver/report: created

Veridata Status files          /u01/ggate/dirver/status: created

Veridata Trace files           /u01/ggate/dirver/trace: created

Stdout files                   /u01/ggate/dirout: created

 

GGSCI (gg1) 2>

 

以上就是GG 的安装,在source 和target database 都执行。

 

二.配置Source database

GoldenGate通过抓取源端数据库重做日志进行分析,将获取的数据应用到目标端,实现数据同步。因此,源数据库需要必须处于归档模式,并启用附加日志和强制日志。

 

2.1 归档模式、附加日志、强制日志

--查看

SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;

LOG_MODE     SUPPLEME FOR

------------ -------- ---

ARCHIVELOG  NO       NO

 

--修改

(1)archivelog

SQL>shutdown immediate

SQL>startup mount

SQL>alter database archivelog;

SQL>alter database open;

(2) force logging

SQL>alterdatabase force logging;

(3)supplemental log data

SQL>alterdatabase add supplemental log data;

 

2.2 Oracle 9i的_LOG_PARALLELISM参数

如果是Oracle 9i的数据库,还需要将_LOG_PARALLELISM 参数设置为1. 因为GG 不支持该值超过1.

If using OracleGoldenGate for an Oracle 9i source database, set the _LOG_PARALLELISMparameter to 1. Oracle GoldenGate does not support values higher than 1.

 

2.3 启用DDL 支持

       GG虽然支持DDL,但是也是有限制的,具体参考:

Oracle Gloden Gate 系列三 --GG 支持与不支持的对象类型与操作 说明

http://blog.csdn.net/tianlesoftware/article/details/6933969

 

GG 支持DDL 也是通过创建一些table 来保存这些DDL 的信息,关于这些table 的具体说明,在如下链接的第二小节:启用GG 对DDL 操作的支持有详细说明:

Oracle Golden Gate 系列四 --GG 安装 与 卸载 理论知识

http://blog.csdn.net/tianlesoftware/article/details/6937183

 

对于这些存放DDL 信息表的管理的理论支持,参考如下链接的第四小结:Managing theOracle DDL replication environment。

Oracle Golden Gate 系列五 --GG 使用配置 说明

http://blog.csdn.net/tianlesoftware/article/details/6947973

 

这块的测试内容会另篇Blog进行测试。

 

 

2.3.1 禁用Recycle Bin

如果启用DDL 支持,必须关闭recycle bin。官网的解释如下:

If the recyclebin is enabled, the Oracle GoldenGate DDL trigger session receives implicitrecycle bin DDL operations that cause the trigger to fail.

 

Oracle 11g:

SQL> alter system set recyclebin=offscope=spfile;

System altered.

 

如果数据库是10g,需要关闭recyclebin并重启;或者手工purge recyclebin。

 

2.3.2 创建存放DDL 信息的user并赋权

SQL> create user ggate identified by ggate default tablespace users temporary tablespace temp;

User created.

SQL> grant connect,resource to ggate;

Grant succeeded.

SQL> grant execute on utl_file to ggate;

Grant succeeded.

 

退出所有使用Oracle 的session,然后使用SYSDBA权限的用户执行如下脚本:

 

gg1:/u01/ggate> echo $GGATE

/u01/ggate

--进入GG的目录,然后调用脚本:

gg1:/home/oracle> cd $GGATE

gg1:/u01/ggate> sqlplus / as sysdba;

SQL*Plus: Release 11.2.0.3.0 Production onTue Nov 8 19:41:58 2011

 

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

 

Connected to:

Oracle Database 11g Enterprise EditionRelease 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Miningand Real Application Testing options

--脚本1:

SQL> @marker_setup.sql;

 

Marker setup script

 

You will be prompted for the name of aschema for the GoldenGate database objects.

NOTE: The schema must be created prior torunning this script.

NOTE: Stop all DDL replication beforestarting this installation.

--输入我们之前创建的用户名:

Enter GoldenGate schema name:ggate

 

Marker setup table script complete, runningverification script...

Please enter the name of a schema for theGoldenGate database objects:

Setting schema name to GGATE

 

MARKER TABLE

-------------------------------

OK

MARKER SEQUENCE

-------------------------------

OK

Script complete.

 

--脚本2:

SQL> @ddl_setup.sql;

 

GoldenGate DDL Replication setup script

 

Verifying that current user has privilegesto install DDL Replication...

 

You will be prompted for the name of aschema for the GoldenGate database objects.

NOTE: For an Oracle 10g source, the systemrecycle bin must be disabled. For Oracle 11g and later, it can be enabled.

--注意这里提示我们在10g里,必须关闭recycle bin,在11g以后的版本,可以不用关闭。

NOTE: The schema must be created prior torunning this script.

NOTE: Stop all DDL replication beforestarting this installation.

 

--提示输入GG的用户:

Enter GoldenGate schema name:ggate

 

You will be prompted for the mode ofinstallation.

To install or reinstall DDL replication,enter INITIALSETUP

To upgrade DDL replication, enter NORMAL

--这里让我们选择安装模式: install 和 reinstall 选择INITIALSETUP

Enter mode of installation:INITIALSETUP

 

Working, please wait ...

Spooling to file ddl_setup_spool.txt

 

Checking for sessions that are holdinglocks on Oracle Golden Gate metadata tables ...

 

Check complete.

 

Using GGATE as a GoldenGate schema name,INITIALSETUP as a mode of installation.

 

Working, please wait ...

 

DDL replication setup script complete,running verification script...

Please enter the name of a schema for theGoldenGate database objects:

Setting schema name to GGATE

 

DDLORA_GETTABLESPACESIZE STATUS:

……

 

STATUS OF DDL REPLICATION

-------------------------------------------------------------------------------------------------------

SUCCESSFUL installation of DDL Replicationsoftware components

 

Script complete.

 

--脚本3:

SQL> @role_setup.sql;

 

GGS Role setup script

 

This script will drop and recreate the roleGGS_GGSUSER_ROLE

To use a different role name, quit thisscript and then edit the params.sql script to change the gg_role parameter tothe preferred name. (Do not run the script.)

 

You will be prompted for the name of aschema for the GoldenGate database objects.

NOTE: The schema must be created prior torunning this script.

NOTE: Stop all DDL replication beforestarting this installation.

--同样输入GG用户名:

Enter GoldenGate schema name:ggate

Wrote file role_setup_set.txt

 

PL/SQL procedure successfully completed.

 

Role setup script complete

 

Grant this role to each user assigned tothe Extract, GGSCI, and Manager processes, by using the following SQL command:

--这里提示我们赋权给相关的用户:

GRANT GGS_GGSUSER_ROLE TO<loggedUser>

where <loggedUser> is the userassigned to the GoldenGate processes.

 

--脚本4:赋权

SQL> grant GGS_GGSUSER_ROLE to ggate;

Grant succeeded.

 

--脚本5:

SQL> @ddl_enable.sql;

Trigger altered.

 

注意这里脚本创建的table都是使用默认的名称,当然也可以修改这些table的默认名,具体这块参考之前的文档中的说明。

 

三.测试GG

经过第一和第二节的配置,GG 的配置基本完成,这里我们开始测试GG。

注意:

(1)    目标库的用户名和对象名称可以与源端不同,关键在于配置文件中要能够正确匹配。

(2)    配置源和目标两端tnsnames,保持互联互通。

 

3.1 在Source 和 Target database上创建测试用户

--source database

SQL> create user sender identified by oracle default tablespace users temporary tablespace temp;

User created.

SQL> grant connect,resource,dba tosender;

Grant succeeded. 

 

--target database

SQL> create user receiver identified byoracle default tablespace users temporary tablespace temp;

User created.

SQL> grant connect,resource,dba toreceiver;

Grant succeeded.

 

3.2 在Source 和Target 上配置Manager

gg1:/home/oracle> cd $GGATE

gg1:/u01/ggate> ggsci

Oracle GoldenGate Command Interpreter forOracle

Version 11.1.1.1OGGCORE_11.1.1_PLATFORMS_110421.2040

Linux, x64, 64bit (optimized), Oracle 11gon Apr 21 2011 22:42:14

 

Copyright (C) 1995, 2011, Oracle and/or itsaffiliates. All rights reserved.

 

GGSCI (gg1) 1> info all

Program    Status      Group       Lag           Time Since Chkpt

MANAGER    STOPPED                                          

GGSCI (gg1) 2> edit params mgr

PORT 7809

--这里我们指定了端口,然后:wq 保存退出。

GGSCI (gg1) 3> start manager

Manager started.

 

以上是在Source 库上执行的,在Target 库上执行同样的操作。

 

3.3 配置SourceDB 的复制队列

 

3.3.1 先连接到数据库,测试连接:

GGSCI (gg1) 10> dblogin useridggate@gg1, password ggate

Successfully logged into database.

 

3.3.2 增加一个抽取:

GGSCI (gg1) 11> add extract ext1,tranlog, begin now

2011-11-08 20:36:47  INFO   OGG-01749  Successfully registeredEXTRACT EXT1 to start managing log retention at SCN 1121060.

EXTRACT added.

 

GGSCI (gg1) 12> add exttrail /u01/ggate/dirdat/lt, extract ext1

EXTTRAIL added


修改抽取进程ext1参数:

GGSCI (gg1) 13> edit params ext1

extract ext1

userid ggate@gg1, password ggate

rmthost gg2, mgrport 7809

rmttrail /u01/ggate/dirdat/lt

ddl include mapped objname sender.*;

table sender.*;

 

GGSCI (gg1) 14> info all

Program    Status      Group       Lag           Time Since Chkpt

MANAGER    RUNNING                                           

EXTRACT    STOPPED     EXT1        00:00:00      00:03:26  

 

3.4  配置TargetDB 同步队列

 3.4.1 在Target 端添加checkpoint表:

GGSCI (gg2) 6> edit params ./GLOBAL

GGSCHEMA ggate

CHECKPOINTTABLE ggate.checkpoint

添加如上2条记录。

 

GGSCI (gg2) 12> dblogin userid ggate@gg2,password ggate

Successfully logged into database.

--说明,这个用户是在Source 库启用DDL 创建的,我在Target 库也创建了这个用户。

GGSCI (gg2) 13> add checkpointtable ggate.checkpoint

Successfully created checkpoint tableGGATE.CHECKPOINT.

 

3.4.2 创建同步队列

GGSCI (gg2) 14> add replicat rep1,exttrail /u01/ggate/dirdat/lt, checkpointtable ggate.checkpoint

REPLICAT added.

 

GGSCI (gg2) 15> edit params rep1

replicat rep1

ASSUMETARGETDEFS

userid ggate@gg2,password ggate

discardfile /u01/ggate/dirdat/rep1_discard.txt,append, megabytes 10

DDL

map sender.*, target receiver.*;

添加如上内容。

 

3.5开启同步

3.5.1 Source DB:

GGSCI (gg1) 15> start extract ext1

Sending START request to MANAGER ...

EXTRACT EXT1 starting

 

GGSCI (gg1) 16> info all

Program    Status      Group       Lag           Time Since Chkpt

MANAGER    RUNNING                                          

EXTRACT    STOPPED     EXT1        00:00:00      00:14:16   

 

GGSCI (gg1) 17> info all

Program    Status      Group       Lag           Time Since Chkpt

MANAGER    RUNNING                                          

EXTRACT    RUNNING     EXT1        00:14:26      00:00:02 

 

3.5.2 Target DB

GGSCI (gg2) 16> start replicat rep1

Sending START request to MANAGER ...

REPLICAT REP1 starting

 

GGSCI (gg2) 17> info all

Program    Status      Group       Lag           Time Since Chkpt

MANAGER    RUNNING                                          

REPLICAT   RUNNING     REP1        00:00:00      00:00:04  

 

3.6 测试Data 复制

我们在Source DB上的sender 用户下创建一张表,然后看这张表是否同步到了Target DB的receiver用户下。

 

--Source DB:

SQL> conn sender/oracle;

Connected.

 

SQL> create table dave as select * fromsys.all_users;

Table created.

 

--Target DB:

SQL> conn receiver/oracle;

Connected.

SQL> select count(*) from dave;

 

 COUNT(*)

----------

       32

 

数据同步过来了,因为我们启用了DDL的支持,所以这里把表给复制过来了。

 

现在我们在Source DB上在插入一些记录,在验证下GG的同步情况:

SQL> insert into dave select * fromsys.all_users;

32 rows created.

SQL> commit;

Commit complete.

 

在Target DB 验证:

SQL> select count(*) from dave;

 COUNT(*)

----------

       32

 

SQL> /

 

 COUNT(*)

----------

       64

 

同步正常,以上就是Oracle to Oracle 下的一个GG 单向复制示例。有关GG的更多内容会继续测试。

 

 

 

0 0
原创粉丝点击