首页 > 代码库 > 1.GoldenGate 简单的一对一配置

1.GoldenGate 简单的一对一配置

一,软件安装
 

源端和目标端均执行(只要修改相应的目录)

 
1.上传软件,放到ogg的安装目录,并解压
 
mkdir /home/oracle/ogg
unzip ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip
tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar
 
2.设置环境变量

export GGATE_HOME=/home/oracle/ogg

export LIBPATH=GGATEHOME:ORACLE_HOME/lib
. .bash_profile 
 
3.进入软件安装目录
 
cd /home/oracle/ogg/
./ggsci 
create subdirs
 
4. 在ORACLE中创建ogg专属用户
 
源端数据库:
 
sqlplus /nolog
conn / as sysdba
create user ogg identified by ogg;
grant connect,resource to ogg;
grant unlimited tablespace to ogg;
grant execute on utl_file to ogg;
grant SELECT ANY DICTIONARY, SELECT ANY TABLE to ogg; 
grant ALTER ANY TABLE to ogg;
grant FLASHBACK ANY TABLE to ogg;
grant EXECUTE on DBMS_FLASHBACK to ogg; 

grant executeon utl_file to ogg;

grant alter any table to ogg;

grant flashback any table to ogg;

grant execute on DBMS_FLASHBACK to ogg;
 
目标端数据库:
 
sqlplus /nolog
conn / as sysdba
create user ogg identified by ogg;

grant connect,resource,unlimited tablespace to ogg;

grant execute on utl_file to ogg;

grant select any dictionary,select any table to ogg;

grant alter any table to ogg;

grant flashback any table to ogg;

grant execute on DBMS_FLASHBACK to ogg;

grant insert any table to ogg;

grant delete any table to ogg;

grant update any table to ogg;

 
5.创建测试表
 
(下面的例子以oracle自带的hr用户为例)
源端测试表:create table test as select object_id from dba_objects where rownum<101;   ---插入100条数据
目标端测试表:create table test as select object_id from dba_objects where 1=2;   --不插入数据
 
二,源端设置
 
1.开启ORACLE归档模式,设置日志模式(归档模式、附加日志、强制日志)

 

    --查看
     select db.LOG_MODE, db.SUPPLEMENTAL_LOG_DATA_MIN, db.FORCE_LOGGING from v$database db
    --修改
    --1)archivelog
    shutdown immediate
    startup mount
    alter database archivelog;
    alter database open;
    --2)force logging
    alter database force logging;
    --3)supplemental log data
    alter database add supplemental log data;
 
2. 配置管理进程
 
EDIT PARAMS MGR

PORT 7809

启动
START MGR
 
3. 添加抽取进程:
 

GGSCI (db11) 31> view param lhremd1

EXTRACT lhremd1
setenv(NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
USERID ogg, PASSWORD ogg
DBOPTIONS ALLOWNOLOGGING 
EXTTRAIL ./dirdat/l1
TABLE hr.*;

 
添加:

GGSCI (sourceserver) > ADD EXTRACT LHREMD1, TRANLOG, BEGIN NOW 
GGSCI (sourceserver) > ADD EXTTRAIL dirdat/l1, EXTRACT LHREMD1, MEGABYTES 100

启动

start ext lhremd1

 

 
4. 打开表的补全日志:
 
GGSCI (dsgdata) 52>add trandata hr.employees 

 
5. 添加投递进程:
 
GGSCI (db11) 32> view param phremd1Extract PHREMD1 ------------------------------------------------------------------- -- Data Pump extract for HR schema ------------------------------------------------------------------- PassThru RmtHost 192.168.1.3, MgrPort 7809 RmtTrail dirdat/l2 Table HR.* ;
 
-----说明:hr用户下所有表中执行的DML操作都可以被复制,但是必须目标端目标表必须存在
 
添加:

GGSCI (sourceserver) > ADD EXTRACT PHREMD1, EXTTRAILSOURCE dirdat/l1 
GGSCI (sourceserver) > ADD RMTTRAIL dirdat/l2, EXTRACT PHREMD1, MEGABYTES 100

#添加一个dp01,从哪里读取什么文件传输到哪里去
 
启动
start ext phremd1
 
二,目标端配置:
 
GGSCI>edit param mgr

PORT 7809
 
GGSCI (oracle11) 3> edit param ./GLOBALS
CHECKPOINTTABLE ogg.checkpoint      ---ogg为管理用户
 
GGSCI>exit         #这里要退出来,下面的ADD CHECKPOINTTABLE才能执行成功,否则会报CHECKPOINTTABLE不存在
 
GGSCI>DBLOGIN USERID ogg, PASSWORD ogg   ## ADD replicat checkpoint table in target system 
 
GGSCI>add checkpointtable ogg.checkpoint
 

GGSCI (10gasm) 3> view param rhremd1  #编辑配置文件,告诉他做什么

Replicat RHREMD1 
------------------------------------------------------------------- 
-- Replicat for HR Schema 
------------------------------------------------------------------- 
SETENV (NLS_LANG = AMERICAN_AMERICA.AL32UTF8) 
USERID ogg, PASSWORD ogg
HandleCollisions 
AssumeTargetDefs 
Map HR.*, Target HR.* ;  ---注意:空格和分号---结构必须相同,名字可以不同

 
GGSCI>ADD REPLICAT RHREMD1, EXTTRAIL dirdat/l2 #要指明提取的队列文件(源端会把数据发送到这里)
 
启动
start rep rhremd1
 
三,测试:
对源端hr.employees 表进行增删改,查看目标端的数据是否发生变化。
 
四,总结
两点注意:使用ASM管理的数据库在源端配置抽取进程的时候必须指定TRANLOGOPTIONS
配置文件中,MAP TEST.TEST,  TARGET TEST.TEST;    ---- 要注意TARGET前面空格和最后的分号不能少
 
关于TRANDATA:http://www.itpub.net/thread-1332238-2-1.html
 
五,关于常用的维护命令
info all
info ext lhremd1
info ext lhremd1,detail
stats ext lhremd1
view report lhremd1
view param lhremd1
info mgr
edit param lhremd1

1.GoldenGate 简单的一对一配置