Golden Gate Software自从被Oracle公司收购后,就代替了Oracle的Stream Replication还有Logic Standby技术成为了逻辑复制技术的首选。Golden Gate支持的数据库和操作系统平台也是颇为广泛,使得Golden Gate在跨平台跨数据库的数据迁移领域,也有着重要地位。
本文将配置对于Oracle数据库的支持DDL语句的单向数据复制技术的配置做详细的介绍。
环境介绍:
Operate System: Red Hat Enterprise Linux 5.5
Database Version: Oracle 11g Release 2
Golden Gate Version: 11 Release 2
Source SID: ora11g01
Source IP Address: 172.25.0.30
Target SID: ora11g02
Target IP Address: 172.25.0.40
一、Oracle Golden Gate原理简介:
与传统的逻辑复制技术相同,Oracle GoldenGate的实现也是通过抽取source端的online redo log或者archive log通过TCP/IP协议传输到Target端,之后在目标端解析应用语句,从而达到了数据复制的效果:
上图则是Oracle GoldenGate的架构图。
Manager: Manger进程是OGG的管理进程,起作用是启动、监控、重启OGG的其他进程,报告错误以及事件,分配存储空间等等。
Extract: 运行在Source端,负责从数据表或者日志中补获数据。
Pump: 一种特殊的Extract进程,将数据的变化量通过TCP/IP协议以block的形式发送到目标端的指定位置,如果不使用trail文件,那么这个过程则是Extract进程捕获数据变化直接传递到Target端。
Trail: 为了更加安全和有效的投递事务信息和数据变化,OGG引入了trail文件的概念,Extract会将数据的变化抽取并生成trail文件(就像OGG格式的归档),又Pump进程传输到Target端。建议OGG开始Trail的功能。
Replicate: 简而言之,就是将Extract或者Pump传递过来的数据变化,及时的重组和应用到目标端的数据库。
二、Oracle Golden Gate的部署
Source端:
1.创建ogg安装目录:
[oracle@ora11g01 ~]$ mkdir -p /u01/ggs/11.2.0
2.解包ogg文件:
[oracle@ora11g01 ~]$ cd /u01/ggs/11.2.0
[oracle@ora11g01 ~]$ tar -zvof ogg112101_fbo_ggs_Linux_x86_ora11g\
.tar
3.设置环境变量
[oracle@ora11g01 ~]$ vi ~/.bash_profile
export PATH=$ORACLE_HOME/bin:/u01/ggs/11.2.0:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local
/lib:/u01/ggs/11.2.0
4.创建工作目录
[oracle@ora11g01 ~]$ pwd
/u01/ggs/11.2.0
[oracle@ora11g01 ~]$ggsci
GGSCI(ora11g01.us.oracle.com)> create subdirs
5.数据库开启归档模式和附加日志
SQL> archive log list
SQL> alter system set log_archive_dest_1=‘localtion=/home/oracle\
flash’;
System Altered.
SQL> alter database add supplemental log data;
Database Altered.
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
Database altered.
6.创建ogg管理用户
SQL> create user ggs identified by ggs;
User Created.
SQL> grant connect,resource to ggs;
Grant succeeded.
SQL> grant execute on utl_file to ggs;
Grant succeeded.
SQL> grant select any dictionary,select any table to ggs;
Grant succeeded.
SQL> grant alter any table to ggs;
Grant succeeded.
SQL> grant flashback any table to ggs;
Grant succeeded.
SQL> grant execute on DBMS_FLASHBACK to ggs;
Grant succeeded.
7.添加表级别trandata
GGSCI(ora11g01.us.oracle.com)> dblogin userid ggs,password ggs
Successfully logged into database.
GGSCI(ora11g01.us.oracle.com)> add trandata njl.*
8.配置manager进程组
GGSCI(ora11g01.us.oracle.com)> edit params mgr
port 7809
dynamicportlist 7800-8000
autorestart extract *,waitminutes 2,retries 5
GGSCI(ora11g01.us.oracle.com)> start mgr
Manager Started.
GGSCI(ora11g01.us.oracle.com)> info all
观察Manager进程的Status是RUNNING则配置成功。
9.配置Extract进程组
GGSCI(ora11g01.us.oracle.com)> edit params ext01
extract ext01
dynamicresolution
userid ggs,password ggs
setenv(ORACLE_SID=ora11g01)
exttrail /u01/ggs/11.2.0/dirdat/et
table njl.*;
GGSCI(ora11g01.us.oracle.com)> add exttrail /u01/ggs/11.2.0/\
dirdat/et,extract ext01
GGSCI(ora11g01.us.oracle.com)> start extract ext01
Extract ext01 starting …
GGSCI(ora11g01.us.oracle.com)> info all
10.配置Pump进程组
GGSCI(ora11g01.us.oracle.com)> edit params pump01
extract pump01
dynamicresolution
userid ggs,password ggs
rmthost 172.25.0.40,mgrport 7809,compress
rmttrail /u01/ggs/11.2.0/dirdat/pt
table njl.*;
GGSCI(ora11g01.us.oracle.com)> add extract pump01,exttrail /u01\
/ggs/11.2.0/dirdat/et
EXTRACT added.
GGSCI(ora11g01.us.oracle.com)> add rmttrail /u01/ggs/11.2.0/dirdat\
/pt,extract pump01
GGSCI(ora11g01.us.oracle.com)> start extract pump01
GGSCI(ora11g01.us.oracle.com)> info all
11.初始化数据
由于在target数据库中并没有原始的数据,我们需要选定一个scn点,来抽取当时的数据,来完成数据的初始化任务,使得目标端数据库有相应的表来供replicate进程应用数据。
这里我们选用expdp来做初始化。
SQL> create directory njl as ‘/home/oracle’;
Directory Created.
SQL> grant all on directory njl to public;
Grant Succeeded.
SQL> select current_scn from v$database;
[oracle@ora11g01 ~] expdp \’/ as sysdba\’ directory=njl
dumpfile=ogg.dmp logfile=ogg.log schemas=NJL
flashback_scn=current_scn
[oracle@ora11g01 ~] scp /home/oracle/ogg.dmp [email protected]:~
SQL(Target DB)> create directory njl as ‘/home/oracle’;
Directory Created.
SQL(Target DB)> grant all on directory njl to public;
Grant Succeeded.
[oracle@ora11g02 ~]impdp \’/ as sysdba\’ directory=njl
dumpfile=ogg.dmp logfile=ogg.log full=y
Target端:
1.创建ogg管理用户,同source端操作
2.添加checkpoint表
[oracle@ora11g01 ~] pwd
/u01/ggs/11.2.0
GGSCI(ora11g02.us.oracle.com)> edit params ./GLOBALS
checkpointtable ggs.checkpoint
GGSCI(ora11g02.us.oracle.com)> exit
[oracle@ora11g01 ~]ggsci
GGSCI(ora11g02.us.oracle.com)> dblogin userid ggs,password ggs
Successfully logged into database.
GGSCI(ora11g02.us.oracle.com)> add checkpointtable
Successfully created checkpoint table table ggs.checkpoint.
3.配置manager进程
GGSCI(ora11g02.us.oracle.com)> edit params mgr
port 7809
dynamicportlist 7800-8000
autostart er *
autorestart extract *,waitminutes 2,retries 5
lagreporthours 1
laginfominutes 3
lagcriticalminutes 5
purgeoldextracts /u01/ggs/11.2.0/dirdat/rt*,usecheckpoints,minkeep\
days 3
GGSCI(ora11g02.us.oracle.com)> start mgr
Manager started.
GGSCI(ora11g02.us.oracle.com)> info all
4.配置replicate
GGSCI(ora11g02.us.oracle.com)> edit params repl
replicat repl
userid ggs,password ggs
assumetargetdefs
reperror default,discard
discardfile /u01/ggs/11.2.0/dirrpt/repl.dsc,append,megabytes 50
dynamicresolution
map njl.* njl.*;
GGSCI(ora11g02.us.oracle.com)> add replicat repl ,exttrail /u01/\
ggs/11.2.0/dirdat/pt
REPLICAT added.
GGSCI(ora11g02.us.oracle.com)> start replicat repl,aftercsn xxxx;
REPLICATE REPL starting …
GGSCI(ora11g02.us.oracle.com)> info all
支持DML语句的OGG配置完毕,自行进行数据的校验。
Oracle Golden Gate配置支持DDL:
Source端:
SQL> alter system set recyclebin=‘off’ scope=spfile
System Altered.
SQL> create tablespace ggs datafile ‘/u01/app/oracle\
/oradata/ora11g01/ggs01.dbf’ size 100M autoextend on;
SQL> alter user ggs default tablespace ggs;
SQL> startup force(这个步骤建议在之前配置DML支持的时候就做\
由于本文讲解的是分开配置,所以在这里做此提示)
GGSCI(ora11g01.us.oracle.com)> edit params ./GLOBALS
ggschema ggs
GGSCI(ora11g01.us.oracle.com)> @marker_setup.sql
输入ggs(之后的所有脚本都输入ggs,ggs是ogg的管理用户)
GGSCI(ora11g01.us.oracle.com)> @ddl_setup.sql
GGSCI(ora11g01.us.oracle.com)> @role_setup.sql
SQL(Source DB)> grant ggs_ggsuser_role to ggs;
Grant Succeeded.
GGSCI(ora11g01.us.oracle.com)> @ddl_enable.sql
GGSCI(ora11g01.us.oracle.com)> @marker_status.sql
GGSCI(ora11g01.us.oracle.com)> edit params ext01
添加 ddl include all
GGSCI(ora11g01.us.oracle.com)> edit params pump01
添加 ddl include all
重启相关进程后,开始进行DDL支持的测试。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31401355/viewspace-2129313/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31401355/viewspace-2129313/