Oracle goldengate Windows平台oracle-oracle单向复制
试验环境:
试验环境 |
源端软件版本 |
目标端软件版本 |
操作系统 |
Windows 2008 R2 Enterprise 64bit |
Windows 2003 Enterprise 32bit |
数据库 |
Oracle 10.2.0.3.0 32bit |
Oracle 11.2.0.3.0 32bit |
GoldenGate |
V11.1.1.1.2 Win_x86_ora10g_32bit |
V11.1.1.1.2 Win_x86_ora11g_32bit |
目标概述
Goldengate最基本的从源端一对一的单向复制,注意其中goldengate版本取决于oracle的版本。
这种场景一般适用于保持目标数据库的实时更新,且目标数据库用来检索,如报表或者分析使用。
Goldengate在Windows平台安装
软件下载
1. 从https://edelivery.oracle.com/下载,目前必须要有足够权限的账号才能下载
2. 从https://support.oracle.com/下载,要有oracle服务账号下载最新的补丁,即可直接使用
3. 从http://www.oracle.com/technetwork/middleware/goldengate/downloads/index.html下载最新版本,同样要有oracle服务账号,登录后用搜狗等下载工具下载。
安装条件
1. 以administrator身份登录系统进行安装,只要安装者属于系统的administrator组就行。
2. 安装Microsoft Visual C ++ 2005 SP1 Redistributable Package,这个是必须的。
安装Goldengate软件
安装方法很简单,只需要把压缩包解压后,把文件放到指定文件夹即可,如c:/gg目录。
源和目标端同样。
1.设置环境变量
在系统属性-高级-环境变量里面设置如下两个环境变量的值,如
ORACLE_HOME=D:\app\Administrator\product\11.2.0\dbhome_1
ORACLE_SID=oratask
2.安装goldengate文件
解压缩到c:/gg目录下,然后cd到c:/gg目录,运行ggsci命令,创建子目录。
c:\gg>ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
Windows (optimized), Oracle 10g on Oct 5 2011 00:50:35
Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
GGSCI (WIN-VRO8RDT77CE) 1>create subdirs
……
主要目录介绍:
dirchk:存放检查点(Checkpoint)文件
dirdat:存放Trail与Extract文件,以后详述
dirdef:通过DEFGEN工具生成的源或目标的数据定义文件
dirpcs:存放进程状态文件
dirprm:存放参数文件
dirrpt:存放进程报告文件
dirsql:存放SQL脚本文件
dirtmp:当事务所需要的内存超过已分配内存时,缺省存储于此。
3.添加manager进行到windows服务
手动指定服务名GGMGR(默认就是GGMGR)。
用edit params ./GLOBALS命令(注意./GLOBALS为大写),进入编辑文件,输入下面内容。
MGRSERVNAME GGMGR
保存退出后,用install addservice命令添加服务
c:\gg>install addservice
Service 'GGMGR' created.
Install program terminated normally.
4.Goldengate实用程序
运行GGSCI(GoldenGate Software Command Interface)命令可以进入Goldengate交互界面,提供多种管理Goldengate的命令,用help命令查看命令使用方法。
GGSCI (WIN-VRO8RDT77CE) 1> help
GGSCI Command Summary:
Object: Command:
SUBDIRS CREATE
ER INFO, KILL, LAG, SEND, STATUS, START, STATS, STOP
EXTRACT ADD, ALTER, CLEANUP, DELETE, INFO, KILL,
LAG, REGISTER, SEND, START, STATS, STATUS, STOP
UNREGISTER
EXTTRAIL ADD, ALTER, DELETE, INFO
GGSEVT VIEW
MANAGER INFO, SEND, START, STOP, STATUS
MARKER INFO
PARAMS EDIT, VIEW
REPLICAT ADD, ALTER, CLEANUP, DELETE, INFO, KILL, LAG, SEND,
START, STATS, STATUS, STOP
REPORT VIEW
RMTTRAIL ADD, ALTER, DELETE, INFO
TRACETABLE ADD, DELETE, INFO
TRANDATA ADD, DELETE, INFO
SCHEMATRANDATA ADD, DELETE, INFO
CHECKPOINTTABLE ADD, DELETE, CLEANUP, INFO
Commands without an object:
(Database) DBLOGIN, LIST TABLES, ENCRYPT PASSWORD, FLUSH SEQUENCE
(DDL) DUMPDDL
(Miscellaneous) FC, HELP, HISTORY, INFO ALL, OBEY, SET EDITOR, SHELL,
SHOW, VERSIONS, ! (note: you must type the word
COMMAND after the ! to display the ! help topic.)
i.e.: GGSCI (sys1)> help ! command
For help on a specific command, type HELP <command> <object>.
Example: HELP ADD REPLICAT
配置oracle数据库
1.在源端打开归档模式
SQL> archive log list
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open
2.在源端库中打开force logging
SQL> select force_logging from v$database;
FOR
---
NO
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FOR
---
YES
3.在源端库中打开supplemental log
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO
SQL> alter database add supplemental log data;
Database altered.
--切换日志,使更改生效
SQL> alter system switch logfile;
System altered.
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
4.在源端库中关闭回收站
SQL> show parameter recyclebin
NAME TYPE VALUE
------------- ----------- ------------------------------
recyclebin string on
SQL> alter system set recyclebin=off;
System altered.
注:如果是oracle 10.1版本使用alter system set “_recyclebin=off”;命令
5.创建goldengate管理用户
--在源端创建ggs用户
SQL> create user ggs identified by ggs default tablespace users temporary tablespace temp;
SQL> grant connect ,resource,unlimited tablespace to ggs;
SQL> grant execute on utl_file to ggs;
SQL> grant select any dictionary,select any table to ggs;
SQL> grant alter any table to ggs;
SQL> grant flashback any table to ggs;
SQL> grant execute on dbms_flashback to ggs;
--在源和目标端创建测试表
SQL> create table demo(id number primary key,ename varchar2(10));
--在目标端创建ggs用户
SQL> create user ggs identified by ggs default tablespace users temporary tablespace temp;
SQL> grant dba to ggs;
6.在源端添加表级的trandata
GGSCI (WIN-VRO8RDT77CE) 1> dblogin userid ggs,password ggs
Successfully logged into database.
GGSCI (WIN-VRO8RDT77CE) 2>add trandata scott.demo
Logging of supplemental redo data enabled for table SCOTT.DEMO.
注:表名可以使用通配符,如add trandata scott.*
7.在目标端添加checkpoint表
--在目标机器上编辑GLOBALS文件,添加一行,checkpointtable ggs.checkpoint
GGSCI (www-7d194fc9aa8) 33> view params ./GLOBALS
MGRSERVNAME GGMGR
checkpointtable ggs.checkpoint
GGSCI (www-7d194fc9aa8) 6>dblogin userid ggs,password ggs
Successfully logged into database.
GGSCI (www-7d194fc9aa8) 7>add checkpointtable ggs.checkpoint
Successfully created checkpoint table GGS.CHECKPOINT.
配置goldengate进程组
一般常用的进程组:
在源端:mgr进程,extract(抽取)进程,pump进程
在目标端:mgr进程,replicat(复制)
拓扑图:Configuration elements for replication to one target
配置源端MGR管理进程
--设置编辑器(可能忽略)
GGSCI> set editor emacs
--配置参数文件
GGSCI (WIN-VRO8RDT77CE) 3>edit params mgr
--添加以下内容保存退出
port 7500 --必须存在的参数
dynamicportlist 7501-7505
autorestart extract *,waitminutes 2,retries 5
GGSCI (WIN-VRO8RDT77CE) 3> start mgr
Starting Manager as service ('GGMGR')...
Service started.
GGSCI (WIN-VRO8RDT77CE) 3>view params mgr
port 7500
dynamicportlist 7501-7505
autorestart extract *,waitminutes 2,retries 5
配置源端Extract抽取进行组
--编辑添加extract进程配置文件
GGSCI (WIN-VRO8RDT77CE) 3>edit params eora
GGSCI (WIN-VRO8RDT77CE) 2>view params eora
extract eora
dynamicresolution
userid ggs,password ggs
--setenv(ORACLE_SID=ORCL)
exttrail c:\gg\dirdat\et
table scott.*;
--添加extract进程
GGSCI (WIN-VRO8RDT77CE) 4> add extract eora,tranlog,begin now
EXTRACT added.
--创建本地trail文件,extract进程组负责写这部分文件,pump进程负责读它:
GGSCI (WIN-VRO8RDT77CE) 5>add exttrail c:\gg\dirdat\et,extract eora
EXTTRAIL added.
--启动extract进程,使用start eora或start ext eora或start extract eora
GGSCI (WIN-VRO8RDT77CE) 5> start eora
配置源端pump进程组
--编辑添加pump进程配置文件
GGSCI (WIN-VRO8RDT77CE) 3>edit params pump_so
GGSCI (WIN-VRO8RDT77CE) 2>view params pump_so
extract Pump_so
Dynamicresolution
Userid ggs,password ggs
rmthost 10.1.5.107, mgrport 7500
--Setenv(ORACLE_SID=ORCL)
rmttrail c:\gg\dirdat\et
Table scott.*;
--添加pump进程
GGSCI (WIN-VRO8RDT77CE) 32>add extract pump_so,exttrailsource c:\gg\dirdat\et
EXTTRAIL added.
--添加该rmttrail
GGSCI (WIN-VRO8RDT77CE) 49>add rmttrail c:\gg\dirdat\et,extract pump_so
RMTTRAIL added.
--启动pump进程
GGSCI (WIN-VRO8RDT77CE) 51>start pump_so
Sending START request to MANAGER ('GGMGR') ...
EXTRACT PUMP_SO starting
GGSCI (WIN-VRO8RDT77CE) 4>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EORA 00:00:00 00:00:06
EXTRACT RUNNING PUMP_SO 00:00:00 00:00:07
注意:如果目标端的mgr进程没有启动,此时启动pump进程ggserr.log日志会报如下错误,pump进程也就无法启动。
pture for Oracle, PUMP_SO.prm: EXTRACT PUMP_SO starting.
2012-04-20 11:21:41 INFO OGG-00993 Oracle GoldenGate Capture for Oracle, PUMP_SO.prm: EXTRACT PUMP_SO started.
2012-04-20 11:21:42 WARNING OGG-01223 Oracle GoldenGate Capture for Oracle, PUMP_SO.prm: TCP/IP error 10061 (由于目标计算机积极拒绝,无法连接。).
2012-04-20 11:21:53 WARNING OGG-01223 Oracle GoldenGate Capture for Oracle, PUMP_SO.prm: TCP/IP error 10061 (由于目标计算机积极拒绝,无法连接。).
配置目标端MGR管理进程
--依据源端的配置,配置目标端mgr进程
GGSCI (www-7d194fc9aa8) 1> edit params mgr
GGSCI (www-7d194fc9aa8) 1>view params mgr
port 7500
dynamicportlist 7501-7505
autostart er *
autorestart extract *,waitminutes 2,retries 5
lagreporthours 1
laginfominutes 3
lagcriticalminutes 5
purgeoldextracts c:\gg\dirdat\et*,usecheckpoints,minkeepdays 3
配置目标端Replicat复制进程组
--编辑添加Replicat进程配置文件
GGSCI (www-7d194fc9aa8) 2> view params repl
replicat repl
userid ggs,password ggs
assumetargetdefs
reperror default,discard
discardfile ./dirrpt/repl.dsc,append,megabytes 50
dynamicresolution
MAP scott.*, target scott.*;
--添加replicat进程
GGSCI (www-7d194fc9aa8) 23>add replicat repl,exttrail c:\gg\dirdat\et,checkpointtable ggs.checkpoint
REPLICAT added.
GGSCI (www-7d194fc9aa8) 25>start repl
Sending START request to MANAGER ...
REPLICAT REPL starting
GGSCI (www-7d194fc9aa8) 26> info repl
REPLICAT REPL Last Started 2012-04-20 13:24 Status ABENDED
Checkpoint Lag 00:00:00 (updated 00:00:29 ago)
Log Read Checkpoint File c:\gg\dirdat\et000000
First Record RBA 0
验证DML复制结果
在源库的scott.demo表上做DML操作,在目标库检查同步结果。
--源库
SQL> conn scott/tiger
已连接。
SQL> insert into demo select 1,'aaa' from dual;
已创建 1行。
SQL> commit;
提交完成。
SQL> insert into demo select 2,'bbb' from dual;
已创建 1行。
SQL> commit;
提交完成。
SQL> Select * From scott.demo;
ID ENAME
---------- ----------
1 aaa
2 bbb
--目标库,过几秒钟后检查
SQL> Select * From scott.demo;
ID ENAME
---------- ----------
1 aaa
2 bbb
配置另一组分发目标进程
下面的实验是在上面的实验的基础上,再增加一个分发目标进程
详细拓扑图:
目标环境:
试验环境 |
目标端软件版本 |
操作系统 |
Redhad Linux 4.7 32bit |
数据库 |
Oracle 10.2.0.1.0 32bit |
GoldenGate |
v11_1_1_0_11_001 linux_x86_ora10g_32bit |
配置源端MGR管理进程
--上面的步骤源端已经配置完成,不需要再配置了。
配置源端Extract抽取进行组
--编辑添加extract进程配置文件
GGSCI (WIN-VRO8RDT77CE) 1>edit params eora2
GGSCI (WIN-VRO8RDT77CE) 2>view params eora2
extract eora
dynamicresolution
userid ggs,password ggs
--setenv(ORACLE_SID=ORCL)
exttrail c:\gg\dirdat\et
table scott.*;
--添加extract进程
GGSCI (WIN-VRO8RDT77CE) 4> add extract eora2,tranlog,begin now
EXTRACT added.
--创建本地trail文件,extract进程组负责写这部分文件,pump进程负责读它:
GGSCI (WIN-VRO8RDT77CE) 5>add exttrail c:\gg\dirdat\et,extract eora2
EXTTRAIL added.
--启动extract进程,使用start eora或start ext eora或start extract eora
GGSCI (WIN-VRO8RDT77CE) 5> start eora
配置源端pump进程组
--编辑添加pump进程配置文件
GGSCI (WIN-VRO8RDT77CE) 3>edit params pump_so2
GGSCI (WIN-VRO8RDT77CE) 2>view params pump_so2
extract Pump_so
Dynamicresolution
Userid ggs,password ggs
rmthost 192.168.1.100, mgrport 7500 –修改ip或hostname
rmttrail /opt/gg/trails/et
Table scott.*;
--添加pump进程
GGSCI (WIN-VRO8RDT77CE) 32>add extract pump_so2,exttrailsource c:\gg\dirdat\et
EXTTRAIL added.
--添加该rmttrail
GGSCI (WIN-VRO8RDT77CE) 49>add rmttrail /opt/gg/trails/et,extract pump_so2
RMTTRAIL added.
--启动pump进程
GGSCI (WIN-VRO8RDT77CE) 51>start pump_so
Sending START request to MANAGER ('GGMGR') ...
EXTRACT PUMP_SO starting
GGSCI (WIN-VRO8RDT77CE) 4>info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EORA 00:00:00 00:00:04
EXTRACT RUNNING EORA2 00:00:00 00:00:04
EXTRACT RUNNING PUMP_SO 00:00:00 00:00:09
EXTRACT RUNNING PUMP_SO2 00:00:00 00:00:09
配置目标端MGR管理进程
--依据源端的配置,配置目标端mgr进程
GGSCI (DB1.lgcns.com) 3> edit params mgr
GGSCI (DB1.lgcns.com) 4>view params mgr
DYNAMICPORTLIST 7840-7914
PORT 7500--注意端口和源mgr一致
PURGEOLDEXTRACTS /opt/gg/trails/w1*, USECHECKPOINTS, MINKEEPFILES 10
PURGEOLDEXTRACTS /opt/gg/trails/w2*, USECHECKPOINTS, MINKEEPFILES 10
PURGEOLDEXTRACTS /opt/gg/trails/et*, USECHECKPOINTS, MINKEEPFILES 10
AUTORESTART ER *, RETRIES 3, WAITMINUTES 5
PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
配置目标端Replicat复制进程组
--编辑添加Replicat进程配置文件
GGSCI (DB1.lgcns.com) 3> edit params repl
GGSCI (DB1.lgcns.com) 4>view params repl
REPLICAT repl
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 scott.* , TARGET scott.* ;
--添加replicat进程
GGSCI (DB1.lgcns.com) 4>add replicat repl,exttrail /opt/gg/trails/et
REPLICAT added.
GGSCI (DB1.lgcns.com) 5>start repl
Sending START request to MANAGER ...
REPLICAT REPL starting
GGSCI (DB1.lgcns.com) 6> info repl
初始化目标数据
1.如果自源端表创建以来没有,抽取进程没有一直停止,可以在目标端取数据时只导入空表即可,在复制进程开始后,源端的所有DML操作会自动应用到目标端。