oracle GoldenGate
http://qjoycn.iteye.com/blog/1279722
在上篇GG 单向复制的示例中,有配置Manager process,这篇具体来看一下Manager Process 的配置。
Oracle Golden Gate 系列六 --11gR2 Ora2Ora 单向复制GG 示例
http://blog.csdn.net/tianlesoftware/article/details/6950018
一.Overview of the Manager process
To configure andrun Oracle GoldenGate, a Manager process must be running on the source andtarget systems. The Manager process performs the following functions:
要配置GG,必须先要在Source和 Target System上部署Manager Process。 该进程执行一下4个函数:
(1)Start Oracle GoldenGateprocesses
--启动GG 进程
(2)Start dynamic processes
--启动动态进程
(3)Perform trail management
--执行trail 管理
(4)Create event, error, andthreshold reports
--创建event,error和threshold报告
There is oneManager for each Oracle GoldenGate installation. One Manager can support multipleOracle GoldenGate extraction and replication processes.
--每个GG 都必须要有一个Manager Process,一个MP可以支持多个GGExtraction 和 Replication 进程。
二.Configuring Manager
To configureManager, create a parameter file by following these steps. If you installed OracleGoldenGate on a UNIX cluster, configure the Oracle GoldenGate Manager process withinthe cluster application as directed by the vendor’s documentation, so thatOracle GoldenGate will fail over properly with the other applications.
--配置Manager,只需要按照以下步骤创建一个参数文件。
To configure Manager
1.From the Oracle GoldenGatedirectory, run the ggsci program to open the Oracle GoldenGate Software CommandInterface, commonly known as GGSCI.
--在GG的根目录运行ggsci命令,因为这个命令会调用其他的命令,如果不是在根目录下执行,虽然在通过PATH变量也可以找到ggsci命令,但是会找不到其他的文件而报错。
2. In GGSCI, issue the following command toedit the Manager parameter file.
EDIT PARAMS MGR
--在ggsci里执行上述命令,编辑Manager 进程参数
3. Add the following parameter to specifythe Manager port number.
PORT<port_number>
PORT defines theport number on which Manager runs on the local system.
--这个端口是本地OS 的端口
Observe these guidelines:
(1)The default port number is7809.
--默认端口是7809
(2)You must specify either thedefault port number or a different one.
--必须指定这个端口为默认端口或者其他端口
(3)Each Manager instance on asystem must use a different port number.
--每个Manager instance必须使用不同的端口
(4)The port must be unreserved andunrestricted. GGSCI uses this port to request Manager to start processes. TheExtract process uses this port to request Manager to start a remote Collectorprocess or an initial-load Replicat process.
--这个端口不能受限
(5)PORT is the only requiredManager parameter.
--端口是Manager 唯一必须指定的参数
NOTE:
The port numberalso must be specified with the MGRPORT argument of the Extract parameter RMTHOST.
--Extrace 的RMTHOST 也必须指定MGRPORT 端口
三.Recommended parameters
The followingparameters are optional, but recommended for the Manager process.
--第二节讲了Manager 必须指定的参数Port,这里讲了一些可选的参数。
(1)USERID: Required if usingOracle GoldenGate DDL support, specify the Manager user and password with the .
--如果使用DDL,需要创建一个用户来保存相关的table,这里指定该用户的用户名和密码
(2)DYNAMICPORTLIST: Use to specifyup to 256 unreserved, unrestricted ports for dynamic TCP/IP communicationsbetween the source and target systems. The Collector,Replicat, and GGSCIprocesses will use these ports. In the absence of DYNAMICPORTLIST, Managertries to start Collector on port 7840. If 7840 is not available, Manager incrementsby one until it finds an available port.
--动态的指定端口在source 和 targetsystems 进行交流。 默认情况下从7840 端口开始,如果该端口不可用,则端口数加1,知道找到一个可用的。
(3)DYNAMICPORTREASSIGNDELAY:Controls how long Manager waits to assign a port that was assigned before.
--控制Manager 等待分配端口的时间。
(4)AUTOSTART: Starts Extract andReplicat processes when Manager starts. This can be useful, for example, if youwant Oracle GoldenGate activities to begin immediately when you start thesystem, assuming Manager is part of the startup routine. You can use multiple AUTOSTARTstatements in the same parameter file.
--在Manager 启动时,自动启动Extract和replicat进程。 这是一个有用的命令,可以将Manager 添加到stratup routine里,这样Manager启动之后,Extrace 和Replicat 也就可以自动启动了。
(5)AUTORESTART: Starts Extract andReplicat processes again after abnormal termination.
--当Extract 和Replicat 进程异常中断后自动启动。
(6)PURGEOLDEXTRACTS: Purges trailfiles when Oracle GoldenGate has finished processing them. Without using PURGEOLDEXTRACTS,no purging is performed, and trail files can consume significant diskspace.Using PURGEOLDEXTRACTS as a Manager parameter is preferred over using theExtract or Replicat version of PURGEOLDEXTRACTS.
--当trail file 处理完后purge它们,如果没有指定该参数,trail file 会占用大量的磁盘空间。 Manager 的PURGEOLDEXTRACTS参数优先级比Extrace 和Replicat 的PURGEOLDEXTRACTS高。 即会先使用Manager的该参数。
NOTE:
When using PURGEOLDEXTRACTS,do not permit trail files to be deleted by any user or program other than OracleGoldenGate. It will cause PURGEOLDEXTRACTS to function improperly.
注意,如果使用PURGEOLDEXTRACTS,那么不允许出GG之外的用户和程序删除trail files 文件。 否则会导致PURGEOLDEXTRACTS异常。
四.Starting Manager
Manager must berunning before you start other Oracle GoldenGate processes. You can startManager from:
--Manager 必须先与GG 进程启动
(1)The command line of any supportedoperating system
(2)GGSCI
(3)The Services applet on aWindows system if Manager is installed as a service. See the Windowsdocumentation or your system administrator.
(4)The Cluster Administrator toolif the system is part of a Windows cluster. This is the recommended way tobring the Manager resource online. See the cluster documentation or your systemadministrator.
(5)The cluster software of a UNIXor Linux cluster. Refer to the documentation provided by the cluster vendor todetermine whether to start Manager from the cluster or by using GGSCI or thecommand line of the operating system.
4.1 To start Manager from the command line
To run Managerfrom the command shell of the operating system, use the following syntax.
mgr paramfile<param file> [reportfile <report file>]
The reportfile argumentis optional and can be used to store the Manager process report in a locationother than the default of the dirrpt directory in the Oracle GoldenGateinstallation location.
4.2 To start Manager from GGSCI
1. From the Oracle GoldenGate directory,run GGSCI.
2. In GGSCI, issue the following command.
START MANAGER
On Windows systems, you can use the BOOTDELAYMINUTES parameter to specify how long aftersystem boot time Manager delays until it starts its processing activities.
NOTE:
When startingManager from the command line or GGSCI on Windows Server2008 with User Account Control enabled, you will receive a UAC prompt requestingyou to allow or deny the program to run.
五.Stopping Manager
Manager runsindefinitely or until stopped by a user. In general, Manager should remain runningwhen there are synchronization activities being performed. Manager performs importantmonitoring and maintenance functions, and processes cannot be started unless Manageris running.
--在停Manager 之前,需要先停GG 进程,因为Manager负责监控和维护其他的进程。
To stop Manager
(1)On UNIX, Linux, and z/OS usingUSS, Manager must be stopped by using the STOP MANAGER command in GGSCI.
STOP MANAGER [!]
Where: ! stops Manager without userconfirmation.
--这里可选的!表示不经过用户确认直接stop
(2)On Windows, if Manager isinstalled as a service, you can stop it from the Services applet. See theWindows documentation or your system administrator.
(3)In a Windows cluster, Managermust only be stopped by taking the Manager resource offline by using theCluster Administrator. If you attempt to stop the Manager service from theGGSCI interface, the cluster monitor interprets it as a resource failure and willattempt to bring the resource online again. If a stop request is repeatedly submittedfrom the GGSCI interface, and the restart threshold of the Manager cluster resourceis exceeded, the cluster monitor marks the Manager resource as failed.
(4)In a UNIX or Linux cluster,refer to the documentation provided by the cluster vendor to determine whetherManager should be stopped from the cluster or by using GGSCI.
-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
Blog: http://blog.csdn.net/tianlesoftware
Weibo: http://weibo.com/tianlesoftware
Email: tianlesoftware@gmail.com
Skype: tianlesoftware
-------加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请----
DBA1 群:62697716(满); DBA2 群:62697977(满)DBA3 群:62697850(满)
DBA 超级群:63306533(满); DBA4 群:83829929(满) DBA5群: 142216823(满)
DBA6 群:158654907(满) DBA7 群:69087192(满)DBA8 群:172855474
DBA 超级群2:151508914 DBA9群:102954821 聊天 群:40132017(满)
http://space.itpub.net/7199859/viewspace-625854
1 oracle GlodenGate概述
GlodenGate是oracle公司收购glodendate的实时异构数据库数据集成产品,目前已经成功应用于美国银行,中华人民共和国海关总署,国家税务总局等。
2 实验环境
两套虚拟机Oracle10.2.0.1+windows 2003 32 bit
源端oracle数据库用户source 主机名为source
目标端oracle数据库用户target 主机名为target
3 Oracle GlodenGate for windows安装
进入以下网站下载oracle glodendate安装软件
http://www.oracle.com/technology/software/products/goldengate/index.html
这里为32bit for windows平台下的安装软件
GGV18162-01ForOracle10g.zip
直接用unzip解压到c:\GG目录下
3.1 创建文件夹
点击运行cmd,进入到c:\gg目录
C:\Documents and Settings\Oracle.XP_ONE>cd ..
C:\Documents and Settings>cd ..
C:\>cd gg
C:\gg>ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version10.4.0.19 Build 002
Windows (optimized), Oracle 10 on Sep 18 2009 15:54:55
Copyright (C) 1995, 2009, Oracle and/or its affiliates. All rights reserved.
GGSCI (source) 1> create subdirs
Creating subdirectories under current directory C:\gg
Parameter files C:\gg\dirprm: created
Report files C:\gg\dirrpt: created
Checkpoint files C:\gg\dirchk: created
Process status files C:\gg\dirpcs: created
SQL script. files C:\gg\dirsql: created
Database definitions files C:\gg\dirdef: created
Extract data files C:\gg\dirdat: created
Temporary files C:\gg\dirtmp: created
Veridata files C:\gg\dirver: created
Veridata Lock files C:\gg\dirver\lock: created
Veridata Out-Of-Sync files C:\gg\dirver\oos: created
Veridata Out-Of-Sync XML files C:\gg\dirver\oosxml: created
Veridata Parameter files C:\gg\dirver\params: created
Veridata Report files C:\gg\dirver\report: created
Veridata Status files C:\gg\dirver\status: created
Veridata Trace files C:\gg\dirver\trace: created
Stdout files C:\gg\dirout: created
Exit;
3.2 在源库创建数据库source用户给予dba权限
Turn on supplemental logging at the database level.
C:\Documents and Settings\Oracle.XP_ONE>sqlplus "/as sysdba"
SQL*Plus: Release10.2.0.1.0 - Production on Sun Jan 24 00:20:38 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10gEnterpriseEdition Release10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create user source identified by source;
User created.
SQL> grant dba,connect,resource to source;
Grant succeeded.
SQL> sqlplus source/source
SQL> conn source/source
Connected.
SQL> alter database add supplemental log data;
Database altered.
SQL> alter system switch logfile;
System altered.
SQL> exit;
Disconnected from Oracle Database10gEnterpriseEdition Release10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
3.3 安装GlodenGate管理进程
Install the glodendate manager process
C:\gg>ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version10.4.0.19 Build 002
Windows (optimized), Oracle 10 on Sep 18 2009 15:54:55
Copyright (C) 1995, 2009, Oracle and/or its affiliates. All rights reserved.
GGSCI (source) 1> edit params ./GLOBAlS
新建个文本文件输入以下内容
MGRSERVNAMEPAUL,然后保存
添加管理进程到windows服务中,以便随windows操作系统自动启动
C:\gg>install addservice addevents
Oracle GoldenGate messages installed successfully.
Service 'PAUL' created.
Install program terminated normally.
然后检查windows服务,已经存在paul这个服务了
PAUL Automatic LOCAL SYSTEM
4 GlodenGate oracle to oracle initial data load using Direct Load方法
4.1 在source端配置mgr端口和启动mgr进程
cd c:\gg
c:\gg\ggsci
GGSCI (source) 2> edit param mgr
输入以下文件,然后按保存
--GoldenGate Manager parameter file
port 7809
输入7809的端口
GGSCI (source) 4> start mgr
Starting Manager as service ('PAUL')...
Service started.
GGSCI (source) 5> info mgr
Manager is running (IP port source.7809).
可以看到启动mgr进程成功
4.2 在source端创建table和加入初始数据
C:\gg>sqlplus source/source
SQL*Plus: Release10.2.0.1.0 - Production on Sun Jan 24 00:51:57 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10gEnterpriseEdition Release10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> @demo_ora_create
Table created.
Table created.
SQL> @demo_ora_insert
1 row created.
1 row created.
1 row created.
1 row created.
Commit complete.
SQL> select * from tcustmer;
CUST NAME CITY ST
---- ------------------------------ -------------------- --
WILL BG SOFTWARE CO. SEATTLE WA
JANE ROCKY FLYER INC. DENVER CO
SQL> select * from tcustord;
CUST ORDER_DA PRODUCT_ ORDER_ID PRODUCT_PRICE PRODUCT_AMOUNT TRANSACTION_ID
---- -------- -------- ---------- ------------- -------------- --------------
WILL94-09-30CAR 144 17520 3 100
JANE95-11-11PLANE 256 133300 1 100
4.3 在source端Add supplemental logging
GGSCI (source) 2> dblogin userid source,password source
Successfully logged into database.
GGSCI (source) 3> add trandata source.tcustmer
Logging of supplemental redo data enabled for table SOURCE.TCUSTMER.
GGSCI (source) 4> add trandata source.tcustord
Logging of supplemental redo data enabled for table SOURCE.TCUSTORD.
验证是否添加supplemental logging是否成功
GGSCI (source) 6> info trandata source.tcust*
Logging of supplemental redo log data is enabled for table SOURCE.TCUSTMER
Logging of supplemental redo log data is enabled for table SOURCE.TCUSTORD
4.4 在target端配置mgr进程和启动mgr进程
Install the glodendate manager process
C:\gg>ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version10.4.0.19 Build 002
Windows (optimized), Oracle 10 on Sep 18 2009 15:54:55
Copyright (C) 1995, 2009, Oracle and/or its affiliates. All rights reserved.
GGSCI (source) 1> edit params ./GLOBAlS
新建个文本文件输入以下内容
MGRSERVNAMEPAUL,然后保存
添加管理进程到windows服务中,以便随windows操作系统自动启动
C:\gg>install addservice addevents
Oracle GoldenGate messages installed successfully.
Service 'PAUL' created.
Install program terminated normally.
然后检查windows服务,已经存在paul这个服务了
PAUL Automatic LOCAL SYSTEM
GGSCI (source) 2> edit param mgr
输入以下文件,然后按保存
--GoldenGate Manager parameter file
port 7809
输入7809的端口
GGSCI (source) 4> start mgr
Starting Manager as service ('PAUL')...
Service started.
GGSCI (source) 5> info mgr
Manager is running (IP port source.7809).
可以看到启动mgr进程成功
4.5 在target端创建target用户和创建表
SQL> create user target identified by target;
User created.
SQL> grant dba,connect,resource to target;
Grant succeeded.
SQL>@demo_ora_create
Verify the results:
SQL> desc tcustmer;
SQL> desc tcustord;
SQL> exit
4.6 Initial data load using direct load method
在source端
GGSCI (source) 7> add extract eini01,sourceistable
EXTRACT added.
GGSCI (source) 8> info extract *,tasks
EXTRACT EINI01 Initialized 2010-01-24 01:18 Status STOPPED
Checkpoint Lag Not Available
Log Read Checkpoint Not Available
First Record Record 0
Task SOURCEISTABLE
GGSCI (source) 9> edit params eini01
输入以下参数,并且保存
--
-- GoldenGate Initial Data Capture
-- for TCUSTMER and TCUSTORD
--
EXTRACT EINI01
USERID source, PASSWORD source
RMTHOST target, MGRPORT 7809
RMTTASK REPLICAT, GROUP RINI01
TABLE source.TCUSTMER;
TABLE source.TCUSTORD;
在target端
GGSCI (target) 6> ADD REPLICAT RINI01,SPECIALRUN
REPLICAT added.
GGSCI (target) 7> INFO REPLICAT *, TASKS
REPLICAT RINI01 Initialized 2010-01-24 01:23 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:00:10 ago)
Log Read Checkpoint Not Available
Task SPECIALRUN
GGSCI (target) 8> edit params RINI01
--
-- GoldenGate Initial Load Delivery
--
REPLICAT RINI01
ASSUMETARGETDEFS
USERID target, PASSWORD target
DISCARDFILE ./dirrpt/RINI01.dsc, PURGE
MAP source.*, TARGET target.*;
在source端
GGSCI (source) 10> START EXTRACT EINI01
Sending START request to MANAGER ('PAUL') ...
EXTRACT EINI01 starting
view report eini01
*********************************************************************
* ** Run Time Statistics ** *
***********************************************************************
Report at 2010-01-24 01:28:40 (activity since 2010-01-24 01:28:27)
Output to RINI01:
From Table SOURCE.TCUSTMER:
# inserts: 2
# updates: 0
# deletes: 0
# discards: 0
From Table SOURCE.TCUSTORD:
# inserts: 2
# updates: 0
# deletes: 0
# discards: 0
view report rini01
*********************************************************************
* ** Run Time Statistics ** *
***********************************************************************
Report at 2010-01-24 01:29:00 (activity since 2010-01-24 01:28:54)
From Table SOURCE.TCUSTMER to TARGET.TCUSTMER:
# inserts: 2
# updates: 0
# deletes: 0
# discards: 0
From Table SOURCE.TCUSTORD to TARGET.TCUSTORD:
# inserts: 2
# updates: 0
# deletes: 0
# discards: 0
在target端查看数据
SQL> select * from tcustmer;
CUST NAME CITY ST
---- ------------------------------ -------------------- --
WILL BG SOFTWARE CO. SEATTLE WA
JANE ROCKY FLYER INC. DENVER CO
SQL> select * from tcustord;
CUST ORDER_DA PRODUCT_ ORDER_ID PRODUCT_PRICE PRODUCT_AMOUNT TRANSACTION_ID
---- -------- -------- ---------- ------------- -------------- --------------
WILL94-09-30CAR 144 17520 3 100
JANE95-11-11PLANE 256 133300 1 100
可以看到从source端到目标端初始化数据成功
5 配置捕捉变化数据进程
Configure Change Capture
5.1 在source端ADD the Extract group
GGSCI (source) 12> ADD EXTRACT EORA01,TRANLOG, BEGIN NOW, THREADS 1
EXTRACT added.
GGSCI (source) 13> info extract eora01
EXTRACT EORA01 Initialized 2010-01-24 01:39 Status STOPPED
Checkpoint Lag 00:00:00 (updated 00:00:32 ago)
Log Read Checkpoint Oracle Redo Logs
2010-01-24 01:39:33 Thread 1, Seqno 0, RBA 0
5.2 在source端create the extract parameter file
GGSCI (source) 14> edit param eora01
--
-- Change Capture parameter file
-- TCUSTMER and TCUSTORD Changes
--
EXTRACT EORA01
USERID source, PASSWORD source
RMTHOST target, MGRPORT 7809
RMTTRAIL ./dirdat/01
TABLE source.TCUSTMER;
TABLE source.TCUSTORD;
5.3 在source端define the glodendate trail
GGSCI (source) 15> ADD RMTTRAIL ./dirdat/01,extract eora01 MEGABYTES 5
RMTTRAIL added.
GGSCI (source) 16> INFO RMTTRAIL *
Extract Trail: ./dirdat/01
Extract: EORA01
Seqno: 0
RBA: 0
File Size:5M
5.4 在source端Start the capture process
GGSCI (source) 17> start extract eora01
Sending START request to MANAGER ('PAUL') ...
EXTRACT EORA01 starting
5.5 在target端编辑globals参数
ggsci
EDIT PARAMS ./GLOBALS
加入以下参数
CHECKPOINTTABLE target.ggschkpt
然后退出
重新登录ggsci才生效
5.6 在target端add a replicat checkpoint table
GGSCI (target) 1> dblogin userid target,password target
Successfully logged into database.
GGSCI (target) 2> add checkpointtable
No checkpoint table specified, using GLOBALS specification (target.ggschkpt)...
Successfully created checkpoint table TARGET.GGSCHKPT.
5.7 在target端add the replicat group
GGSCI (target) 3> ADD REPLICAT RORA01,EXTTRAIL ./dirdat/01
REPLICAT added.
5.8 Create Replicat parameter file
GGSCI (target) 4> edit param rora01
--
-- Change Delivery parameter file to apply
-- TCUSTMER and TCUSTORD Changes
--
REPLICAT RORA01
USERID target, PASSWORD target
HANDLECOLLISIONS
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/RORA01.DSC, PURGE
MAP source.tcustmer, TARGET target.tcustmer;
MAP source.tcustord, TARGET target.tcustord;
5.9 Start the Replicat process
GGSCI (target) 6> info replicat rora01
REPLICAT RORA01 Last Started 2010-01-24 01:59 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:03 ago)
Log Read Checkpoint File ./dirdat/01000000
First Record RBA 886
5.10在source端新增加些数据和target端验证数据
C:\gg>sqlplus source/source
SQL*Plus: Release10.2.0.1.0 - Production on Sun Jan 24 02:00:32 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database10gEnterprise Edition Release10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> @demo_ora_misc
1 row created.
1 row created.
1 row created.
Commit complete.
1 row created
1 row created.
1 row created.
Commit complete.
1 row updated.
1 row updated.
1 row updated.
1 row updated.
Commit complete.
1 row deleted.
1 row deleted.
Commit complete.
3 rows deleted.
Rollback complete.
SQL>
查看结果:
SQL> select * from tcustmer;
CUST NAME CITY ST
---- ------------------------------ -------------------- --
DAVE DAVE'S PLANES INC. TALLAHASSEE FL
BILL BILL'S USED CARS DENVER CO
ANN ANN'S BOATS NEW YORK NY
WILL BG SOFTWARE CO. SEATTLE WA
JANE ROCKY FLYER INC. DENVER CO
SQL> select * from tcustord;
CUST ORDER_DA PRODUCT_ ORDER_ID PRODUCT_PRICE PRODUCT_AMOUNT TRANSACTION_ID
---- -------- -------- ---------- ------------- -------------- --------------
BILL95-12-31CAR 765 14000 3 100
BILL96-01-01TRUCK 333 25000 15 100
WILL94-09-30CAR 144 16520 3 100
GGSCI (source) 21> send extract eora01,report
Sending REPORT request to EXTRACT EORA01 ...
Request processed.
GGSCI (source) 22> view report eora01
Report at 2010-01-24 02:04:38 (activity since 2010-01-24 02:00:53)
Output to ./dirdat/01:
From Table SOURCE.TCUSTMER:
# inserts: 3
# updates: 1
# deletes: 0
# discards: 0
From Table SOURCE.TCUSTORD:
# inserts: 3
# updates: 3
# deletes: 2
# discards: 0
在target端验证数据是否传过来
SQL> select * from tcustmer;
CUST NAME CITY ST
---- ------------------------------ -------------------- --
WILL BG SOFTWARE CO. SEATTLE WA
JANE ROCKY FLYER INC. DENVER CO
DAVE DAVE'S PLANES INC. TALLAHASSEE FL
BILL BILL'S USED CARS DENVER CO
ANN ANN'S BOATS NEW YORK NY
SQL> select * from tcustord;
CUST ORDER_DA PRODUCT_ ORDER_ID PRODUCT_PRICE PRODUCT_AMOUNT TRANSACTION_ID
---- -------- -------- ---------- ------------- -------------- --------------
WILL94-09-30CAR 144 16520 3 100
BILL95-12-31CAR 765 14000 3 100
BILL96-01-01TRUCK 333 25000 15 100
GGSCI (target) 7> SEND REPLICAT RORA01,report
Sending REPORT request to REPLICAT RORA01 ...
Request processed.
GGSCI (target) 8> view report rora01
Reading ./dirdat/01000000, current RBA 2960, 12 records
Report at 2010-01-24 02:08:17 (activity since 2010-01-24 02:01:14)
From Table SOURCE.TCUSTMER to TARGET.TCUSTMER:
# inserts: 3
# updates: 1
# deletes: 0
# discards: 0
From Table SOURCE.TCUSTORD to TARGET.TCUSTORD:
# inserts: 3
# updates: 3
# deletes: 2
# discards: 0
可以看到数据已经实时传送过来 。
http://space.itpub.net/40239/viewspace-660563
Oracle GoldenGate软件基于数据库日志结构变化,通过解析源端在线日志或归档日志获得数据增量,再将这些变化应用到目标数据库,从而实现源库和目标库的数据同步。下面通过一个简单的示例,详细介绍利用GoldenGate实现Oracle数据库之间的同步。基本架构如下图所示:
1. 安装
1.1 下载介质
GoldenGate的安装介质可以从Oracle的官网上下载。
http://www.oracle.com/technetwork/middleware/goldengate/overview/index.html
1.2 配置GoldenGate用户
下载完成后将其拷贝到源和目标的相应位置解压完成后,即可以开始进行配置。
# useradd -g oinstall -G dba ggate
# su – ggate
$ mkdir /u01/app/oracle/ggate
$ cd /u01/app/oracle/ggate
$ tar ……
注意,如果使用Oracle 11g的数据库,需要创建一个link文件。
$ ln -s /u01/app/oracle/product/11.2.0/db_1/lib/libnnz11.so -
/u01/app/oracle/product/11.2.0/db_1/lib/libnnz10.so$ vi ~/.bash_profile
添加如下的内容:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/u01/app/oracle/ggate
export GGATE=/u01/app/oracle/ggate
1.3 创建目录
使用ggsci工具,创建必要的目录。
$ cd /u01/app/oracle/ggate
$ ./ggsciOracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.0.0 Build 078
Linux, x86, 32bit (optimized), Oracle 10 on Jul 28 2010 13:24:18Copyright (C) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
GGSCI (gridcontrol) 1> create subdirs
至此,GoldenGate基本的安装完成。
Note. 此部分需要在源端和目标端完成。
2. 源数据库配置
GoldenGate主要通过抓取源端数据库重做日志进行分析,将获取的数据应用到目标端,实现数据同步。因此,为了让GoldenGate能够正常工作,源数据库需要进行一定配置。
2.1 设置源库为归档模式
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
2.2 开启minimal supplemental logging
SQL> alter database add supplemental log data;
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
SUPPLEME
——–
YES
2.3 关闭数据库的recyblebin
SQL> alter system set recyclebin=off scope=spfile;
如果数据库是10g,需要关闭recyclebin并重启;或者手工purge recyclebin。
2.4 配置复制的DDL支持
SQL> create user ggate identified by ggate default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to ggate;
SQL> grant execute on utl_file to ggate;SQL> @$GGATE/marker_setup.sql;
SQL> @$GGATE/ddl_setup.sql;
SQL> @$GGATE/role_setup.sql;
SQL> grant GGS_GGSUSER_ROLE to ggate;
SQL> @$GGATE/ddl_enable.sql;
2.5 创建源端和目标端的测试用户
source
SQL> create user sender identified by oracle default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to sender;
destination
SQL> create user receiver identified by oracle default tablespace users temporary tablespace temp;
SQL> grant connect,resource,unlimited tablespace to receiver;
3. 配置manager
在源端和目标端分别执行下面的步骤。
3.1 创建manager
[ggate@gridcontrol gg]$ ./ggsci
GGSCI (gridcontrol) 1> info all
Program Status Group Lag Time Since Chkpt
MANAGER STOPPEDGGSCI (gridcontrol) 2> edit params mgr
PORT 7809
ggate (gridcontrol) 3> start manager
Manager started.
4. 配置源端复制队列
GGSCI (gridcontrol) 1> add extract ext1, tranlog, begin now
EXTRACT added.
GGSCI (gridcontrol) 2> add exttrail /u01/app/oracle/ggate/dirdat/lt, extract ext1
EXTTRAIL added.
GGSCI (gridcontrol) 3> edit params ext1
extract ext1
userid ggate@source, password oracle
rmthost centos4, mgrport 7809
rmttrail /u01/app/oracle/ggate/dirdat/lt
ddl include mapped objname sender.*;
table sender.*;GGSCI (gridcontrol) 6> info all
Program Status Group Lag Time Since Chkpt
MANAGER STOPPED
EXTRACT STOPPED EXT1 00:00:00 00:10:55
5. 配置目标端同步队列
5.1 在目标端添加checkpoint表
[oracle@centos4 ggate]$ ./ggsci
GGSCI (centos4) 1> edit params ./GLOBAL –添加下列内容
GGSCHEMA ggate
CHECKPOINTTABLE ggate.checkpoint
GGSCI (centos4) 2> dblogin userid ggate@target
Password:Successfully logged into database.
GGSCI (centos4) 3> add checkpointtable ggate.checkpoint
Successfully created checkpoint table GGATE.CHECKPOINT.
5.2 创建同步队列
GGSCI (centos4) 4> add replicat rep1, exttrail /u01/app/oracle/ggate/dirdat/lt, checkpointtable ggate.checkpoint
REPLICAT added.GGSCI (centos4) 5> edit params rep1
replicat rep1
ASSUMETARGETDEFS
userid ggate@target, password ggate
discardfile /u01/app/oracle/ggate/dirdat/rep1_discard.txt, append, megabytes 10
DDL
map sender.*, target receiver.*;
6. 开启同步
GGSCI (gridcontrol) 14> start extract ext1
GGSCI (gridcontrol) 15> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXT1 00:00:00 00:00:05
GGSCI (centos4) 7> start replicat rep1
GGSCI (centos4) 8> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REP1 00:00:00 00:00:00
7. 验证结果
源端:
SQL> create table sender.test_tab_1 (id number,rnd_str varchar2(12));
SQL> insert into sender.test_tab_1 values (1,’test_1′);
SQL> commit;
目标端:
SQL> select * from receiver.test_tab_1;
ID RND_STR
———- ————
1 test_1