测试环境:
OS: Redhat 6.3 64bit
[root@orcl1 ~]# uname -a
Linux orcl1 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
DB: Oracle 11.2.0.4 64bit
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
以下操作在源库和目标库都要执行
安装GoldenGate软件
1.1解压安装
[oracle@orcl1 ~]$ mkdir -p /u01/ggate/
[oracle@orcl1 ggate]$ cd /u01/ggate/
[oracle@orcl1 ggate]$ unzip ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip
[oracle@orcl1 ggate]$ tar xvf fbo_ggs_Linux_x64_ora11g_64bit.tar
1.2添加环境变量
在/home/oracle/.bash_profile文件里添加如下内容:
export PATH=/u01/ggate:$PATH
export LD_LIBRARY_PATH=/u01/ggate:$LD_LIBRARY_PATH
export GGATE=/u01/ggate
1.3 创建源端和目标端ogg目录
[oracle@orcl1 ggate]$ ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FB
Linux, x64, 64bit (optimized), Oracle 11g on Apr 23 2012 08:32:14
Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
GGSCI (orcl1) 1> create subdirs
Creating subdirectories under current directory /u01/ggate
Parameter files /u01/ggate/dirprm: already exists
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
Stdout files /u01/ggate/dirout: created
配置goldengate
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;
如果启用DDL 支持,必须关闭recycle bin
Oracle 11g:
SQL> alter system set recyclebin=off scope=spfile;
System altered.
SQL> create user ggate identified by ggate default tablespace users temporary tablespace temp;
User created.
2.3 进入GGATE目录,以sysdba用户执行脚本(/u0/ggate/):
@maker_setup.sql-------ddl_setup.sql-------role_setup.sql------grant GGS_GGSUSER_ROLE to ggate;-----@ddl_enable.setup.sql
2.4 ( 配置源和目标两端tnsnames,保持互联互通。
测试goldengate
3.4.1 在Target 端添加checkpoint表:
GGSCI (orcl2) 20> edit params ./GLOBALS
CHECKPOINTTABLE ggate.checkpoint
GGSCI (orcl2) 12> dblogin userid ggate,password ggate
Successfully logged into database.
--说明,这个用户是在Source 库启用DDL 创建的,我在Target 库也创建了这个用户。
GGSCI (orcl2) 13> add checkpointtable ggate.checkpoint
Successfully created checkpoint tableGGATE.CHECKPOINT.
3.4.2 创建同步队列
GGSCI (orcl2) 41> view params rep1
replicat rep1
ASSUMETARGETDEFS
userid ggate,password ggate
discardfile /u01/ggate/dirdat/rep1_discard.txt,append, megabytes 10
DDL
map scott.*, target scott.*;
GGSCI(orcl2) 14> add replicat rep1,exttrail /u01/ggate/dirdat/lt, checkpointtable ggate.checkpoint
REPLICAT added.
3.4.3 开启服务
3.4.4 验证数据同步:
源库:
GGSCI (orcl1) 56> info ext1
EXTRACT EXT1 Last Started 2014-10-22 13:04 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:20:46 ago)
Log Read Checkpoint Oracle Redo Logs
2014-10-22 12:44:01 Seqno 28, RBA 13812736
SCN 0.1074279 (1074279)
目标库:
GGSCI (orcl2) 47> info rep1
REPLICAT REP1 Last Started 2014-10-22 10:53 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:05 ago)
Log Read Checkpoint File /u01/ggate/dirdat/lt000001
2014-10-22 13:04:59.361201 RBA 1072
DML测试
(源库)SQL> insert into t select * from emp;
14 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from t;
COUNT(*)
----------
14
(目标库)
SQL> select count(*) from t;
COUNT(*)
----------
14==>>DML操作同步成功
DDL测试
SQL> drop table t;(源库)
Table dropped.
SQL> desc t;
ERROR:
ORA-04043: object t does not exist(目标库)==>>DDL操作同步成功
--THE END--