环境说明: Linux为Linux 2.6.32-573.el6.x86_64 Oracle为 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

ogg为 ogg112101_fbo_ggs_Linux_x64_ora11g_64bit
10.100.25.14 (原库ip) 10.100.25.16(目标库ip)

说明: goldengate为ogg管理用户 oggdemo为生产用户

源库、目标库都操作:

1. 上传ogg安装包与安装ogg软件。

[oracle@11g ~]$ mkdir ogg

[oracle@11g ~]$ cd ogg
[oracle@11g ogg]$ ls
ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip

[oracle@11g ogg]$ unzip ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip
Archive: ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip
inflating: fbo_ggs_Linux_x64_ora11g_64bit.tar
inflating: OGG_WinUnix_Rel_Notes_11.2.1.0.1.pdf
inflating: Oracle GoldenGate 11.2.1.0.1 README.txt
inflating: Oracle GoldenGate 11.2.1.0.1 README.doc
[oracle@11g ogg]$ tar vxf fbo_ggs_Linux_x64_ora11g_64bit.tar
UserExitExamples/
UserExitExamples/ExitDemo_more_recs/
UserExitExamples/ExitDemo_more_recs/Makefile_more_recs.HPUX
UserExitExamples/ExitDemo_more_recs/Makefile_more_recs.SOLARIS
。。。。省略大量输出。。。。。
ucharset.h
ulg.sql
usrdecs.h
zlib.txt

2. 数据库为ogg传递数据做环境调整。 (归档,数据库级最小附加日志)

[oracle@11g ogg]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Nov 9 03:03:20 2014

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 21
Next log sequence to archive 23
Current log sequence 23
SQL> alter database add supplemental log data;
Database altered.

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
System altered.

3. 创建专用的ogg表空间与ogg用户,ogg用户授权 (以后卸载ogg直接删除表空间即可)

SQL> create tablespace goldgate datafile '/home/oracle/app/oradata/orcl/ogg01.dbf' size 2G AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
Tablespace created.

SQL> CREATE USER goldengate IDENTIFIED BY goldengate DEFAULT TABLESPACE goldgate;
User created.

SQL> GRANT CONNECT TO goldengate;
Grant succeeded.

SQL> GRANT CREATE SESSION TO goldengate;
Grant succeeded.

SQL> GRANT ALTER SESSION TO goldengate;
Grant succeeded.

SQL> GRANT RESOURCE TO goldengate;
Grant succeeded.

SQL> GRANT SELECT ANY DICTIONARY TO goldengate;
Grant succeeded.

SQL> GRANT SELECT ANY TABLE TO goldengate;
Grant succeeded.

SQL> GRANT FLASHBACK ANY TABLE TO goldengate;
Grant succeeded.

SQL> GRANT ALTER ANY TABLE TO goldengate;
Grant succeeded.

说明:
在goldengate目录下,执行 ./ggsci 进入命令行界面,左侧提示出现GGSCI (myhost) 1>,
表示进入成功
如果ggsci进入出错,设置一下环境变量:
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

[oracle@11g ~]$ cd ogg --验证是否可以进入ggsci命令界面
[oracle@11g ogg]$ ./ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230_FBO
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 (11g) 1> -- 成功进入界面

SQL> GRANT INSERT ANY TABLE TO goldengate;
Grant succeeded.

SQL> GRANT UPDATE ANY TABLE TO goldengate;
Grant succeeded.

SQL> GRANT DELETE ANY TABLE TO goldengate;
Grant succeeded.
———————————————————————————————————————————————————————————————
4. 创建ogg子目录

源库与目标库都执行如下:

GGSCI (11g) 3> create subdirs
Creating subdirectories under current directory /home/oracle/ogg
Parameter files /home/oracle/ogg/dirprm: already exists
Report files /home/oracle/ogg/dirrpt: created
Checkpoint files /home/oracle/ogg/dirchk: created
Process status files /home/oracle/ogg/dirpcs: created
SQL script files /home/oracle/ogg/dirsql: created
Database definitions files /home/oracle/ogg/dirdef: created
Extract data files /home/oracle/ogg/dirdat: created
Temporary files /home/oracle/ogg/dirtmp: created
Stdout files /home/oracle/ogg/dirout: created

参数说明:

该命令会在OGG安装目录下建立若干子目录,其中几个主要目录如下所示:
dirchk:用于存放各个进程的检查点
dirdat:用于存放数据队列文件
dirprm:用于存放各进程参数文件
dirrpt:用于存放各进程报告
dirpcs:存放各个正在运行的进程信息

5. 创建mgr进程

GGSCI (11g) 4> edit param mgr (--在mgr文件中加入 port 7809)
GGSCI (11g) 8> view param mgr
port 7809

GGSCI (11g) 5> start mgr
Manager started.

GGSCI (11g) 6> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING

————————————————————————————————————————————————————

源库操作:

6. 创建oggdemo测试用户

SQL> create user oggdemo identified by oggdemo;
User created.

SQL> grant dba to oggdemo;
Grant succeeded.

SQL> conn oggdemo;
Enter password:
Connected.

SQL> create table oggdemo(id int);
Table created.

7. GGSCI命令行中登录数据库,为所有要复制的数据表添加trandata

GGSCI (11g) 9> dblogin userid oggdemo , password oggdemo
Successfully logged into database.

GGSCI (11g) 10> add trandata oggdemo.oggdemo
2014-11-09 04:12:37 WARNING OGG-00869 No unique key is defined for table 'OGGDEMO'. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key.
Logging of supplemental redo data enabled for table OGGDEMO.OGGDEMO.

———————————————————————————————————————————————————————————————

目标端操作:

SQL> create user oggdemo identified by oggdemo;
User created.

SQL> grant dba to oggdemo;
Grant succeeded.

SQL> conn oggdemo;
Enter password:
Connected.

SQL> create table oggdemo(id int);
Table created.

————————————————————————————————————————————————————————

源库操作:

8. 创建ext进程,tail文件,data_pump进程

GGSCI (11g) 11> add ext exta, tranlog, begin now
EXTRACT added.

GGSCI (11g) 12> add exttrail /home/oracle/ogg/dirdat/la, ext exta, MEGABYTES 20 -- 创建源trail文件
EXTTRAIL added.

GGSCI (11g) 13> add extract dpea, EXTTRAILSOURCE /home/oracle/ogg/dirdat/la -- 创建data_pump进程
EXTRACT added.

GGSCI (11g) 14> add rmttrail /home/oracle/ogg/dirdat/ra, ext dpea, MEGABYTES 20 --创建目标端trail文件
RMTTRAIL added.

GGSCI (11g) 15> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED DPEA 00:00:00 00:02:48
EXTRACT STOPPED EXTA 00:00:00 00:09:36

GGSCI (11g) 17> edit param exta --exta文件添加内容显示如下

GGSCI (11g) 35> view param exta

EXTRACT exta
setenv (NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
setenv (ORACLE_SID = orcl)
USERID goldengate, PASSWORD goldengate
EXTTRAIL /home/oracle/ogg/dirdat/la
dynamicresolution
table oggdemo.oggdemo;
TRANLOGOPTIONS EXCLUDEUSER goldengate

GGSCI (11g) 36> edit param dpea --dpea文件添加内容显示如下

GGSCI (11g) 39> view param dpea
extract dpea
setenv (NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
passthru
rmthost 10.100.25.16,mgrport 7809, compress
rmttrail /home/oracle/ogg/dirdat/ra
dynamicresolution
table oggdemo.oggdemo;

参数说明:

passthru表示本进程是一个传输进程data pump,无需跟数据库交互,只需要搬运数据即可;
因为data pump要传输数据到目标,所以需要配置rmthost和rmttrail指定目标主机和队列信息

———————————————————————————————————————————————————————————

目标数据库操作:

9. 创建目标数据库的replicate进程
GGSCI (11g) 6> add rep repa, exttrail /home/oracle/ogg/dirdat/ra, nodbcheckpoint
REPLICAT added.

参数说明:

repa为进程名,一般为rep开头表示是replicat进程,后面可以加1-2位字符标识,一般与ext进程对应;

exttrail表示要抽取的数据队列,注意是目标端的队列位置;

nodbcheckpoint表示不使用数据库检查点。

GGSCI (11g) 17> edit param repa -- repa文件添加内容显示如下

GGSCI (11g) 20> view param repa

replicat repa
setenv (NLS_LANG = AMERICAN_AMERICA.ZHS16GBK)
setenv (ORACLE_SID = orcl)
userid goldengate, password goldengate
reperror default,abend
discardfile /home/oracle/ogg/dirrpt/repa.dsc,append, megabytes 10
assumetargetdefs
dynamicresolution
map oggdemo.oggdemo, target oggdemo.oggdemo;

ok,至此单向复制已经配置完毕。
——————————————————————————————————————

下面配置反方复制:

(原目标库)源库操作:

10. 创建ext进程,tail文件,data_pump进程

GGSCI (11g) 11> add ext extb, tranlog, begin now
EXTRACT added.

GGSCI (11g) 12> add exttrail /home/oracle/ogg/dirdat/lb, ext extb, MEGABYTES 20 -- 创建源trail文件
EXTTRAIL added.

GGSCI (11g) 13> add extract dpeb, EXTTRAILSOURCE /home/oracle/ogg/dirdat/lb -- 创建data_pump进程
EXTRACT added.

GGSCI (11g) 14> add rmttrail /home/oracle/ogg/dirdat/rb, ext dpeb, MEGABYTES 20 --创建目标端trail文件
RMTTRAIL added.

GGSCI (11g) 17> edit param extb --extb文件添加内容显示如下

GGSCI (11g) 35> view param extb

EXTRACT extb
setenv (NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
setenv (ORACLE_SID = orcl)
USERID goldengate, PASSWORD goldengate
EXTTRAIL /home/oracle/ogg/dirdat/lb
dynamicresolution
table oggdemo.oggdemo;
TRANLOGOPTIONS EXCLUDEUSER goldengate

GGSCI (11g) 36> edit param dpeb --dpeb文件添加内容显示如下

GGSCI (11g) 39> view param dpeb
extract dpeb
setenv (NLS_LANG = AMERICAN_AMERICA.ZHS16GBK )
passthru
rmthost 10.100.25.14,mgrport 7809, compress
rmttrail /home/oracle/ogg/dirdat/rb
dynamicresolution
table oggdemo.oggdemo;

参数说明:

passthru表示本进程是一个传输进程data pump,无需跟数据库交互,只需要搬运数据即可;
因为data pump要传输数据到目标,所以需要配置rmthost和rmttrail指定目标主机和队列信息

————————————————————————————————————————————————————————————

(原原库)目标数据库操作:

11. 创建目标数据库的replicate进程

GGSCI (11g) 6> add rep repb, exttrail /home/oracle/ogg/dirdat/rb, nodbcheckpoint
REPLICAT added.

参数说明:

repa为进程名,一般为rep开头表示是replicat进程,后面可以加1-2位字符标识,一般与ext进程对应;
exttrail表示要抽取的数据队列,注意是目标端的队列位置;
nodbcheckpoint表示不使用数据库检查点。

GGSCI (11g) 17> edit param repb -- repb文件添加内容显示如下

GGSCI (11g) 20> view param repb
replicat repb
setenv (NLS_LANG = AMERICAN_AMERICA.ZHS16GBK)
setenv (ORACLE_SID = orcl)
userid goldengate, password goldengate
reperror default,abend
discardfile /home/oracle/ogg/dirrpt/repb.dsc,append, megabytes 10
assumetargetdefs
dynamicresolution
map oggdemo.oggdemo, target oggdemo.oggdemo;

ok,至此双向复制已经配置完成
——————————————————————————————

12. 测试

源库:
GGSCI (11g) 12> start er *

Sending START request to MANAGER ...
EXTRACT DPEA starting

Sending START request to MANAGER ...
EXTRACT EXTA starting

Sending START request to MANAGER ...
REPLICAT REPB starting

GGSCI (11g) 10> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DPEA 00:00:00 00:00:10
EXTRACT RUNNING EXTA 00:00:00 00:00:02
REPLICAT RUNNING REPB 00:00:00 00:00:04

目标库:

GGSCI (11g) 12> start er *
Sending START request to MANAGER ...
EXTRACT DPEA starting
Sending START request to MANAGER ...
EXTRACT EXTA starting
Sending START request to MANAGER ...
REPLICAT REPB starting

GGSCI (11g) 10> info all

Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DPEA 00:00:00 00:00:10
EXTRACT RUNNING EXTA 00:00:00 00:00:02
REPLICAT RUNNING REPB 00:00:00 00:00:04

源库:

SQL> select * from oggdemo;
no rows selected

目标库:

SQL> select * from oggdemo;
no rows selected

源库:

SQL> insert into oggdemo values(1);
1 row created.

ok,双向复制测试成功。 说明这里作者只配置了DML操作,关于DDL操作还需要进一步配置。 转载请标明出处。

SQL> commit;
Commit complete.

SQL> select * from oggdemo;
ID
----------
1

目标库:
SQL> select * from oggdemo;

ID
----------
1

SQL> insert into oggdemo values(2);
1 row created.

SQL> commit;
Commit complete.

SQL> select * from oggdemo;
ID
----------
1
2

源库:
SQL> select * from oggdemo;
ID
----------
2
1

单机11g ogg 双向DML复制的更多相关文章

  1. 【OGG】OGG的单向DML复制配置(一)

    [OGG]OGG的单向DML复制配置(一) 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识, ...

  2. MySQL 数据库双向同步复制

    MySQL 复制问题的最后一篇,关于双向同步复制架构设计的一些设计要点与制约. 问题和制约 数据库的双主双写并双向同步场景,主要考虑数据完整性.一致性和避免冲突.对于同一个库,同一张表,同一个记录中的 ...

  3. MySQL主从双向同步复制

    本文介绍了mysql主从,实现mysql的双向同步复制. MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日 ...

  4. 11g 使用rman duplicate复制数据库,创建辅助实例

    一,创建所需目录 1)创建审计文件目录 PROD1@dbrac1 /dsg/oracle11$ cd $ORACLE_BASE/admin PROD1@dbrac1 /u01/app/oracle/a ...

  5. 桌面远程连接阿里云服务器(windows)后丧失了双向文件复制粘贴功能的解决方案(第一条博客!)

    近日应公司要求,需在windows服务器上架设一个交易中介软件. 过程之一:将软件压缩文件传到服务器上. 问题:在“运行”对话框通过输入'mstsc' 创建远程连接以后,出现本地桌面与服务器之间无法物 ...

  6. Oracle 11g OGG 修改 trail 文件大小

    OGG 修改 trail 文件大小 2018-06-11 15:14 380 0 原创 GoldenGate 本文链接:https://www.cndba.cn/leo1990/article/285 ...

  7. Oracle 11g ogg单表初始化步骤

    ogg单表初始化步骤 2018-06-08 14:55 296 0 原创 GoldenGate 本文链接:https://www.cndba.cn/leo1990/article/2842 1.ogg ...

  8. Oracle 11g OGG mgr定期清理tail 文件

    OGG mgr定期清理tail 文件 2018-06-11 11:58 440 0 原创 GoldenGate 本文链接:https://www.cndba.cn/leo1990/article/28 ...

  9. OGG复制进程延迟高,优化方法一(使用索引)

    日常运维过程中,可能发现OGG同步进程延迟很高: 本篇介绍其中的一种方式. OGG复制进程,或者说同步进程及通过解析ogg trail文件,输出dml语句,在目标库执行dml操作,那么延迟高可能性其一 ...

随机推荐

  1. webStorm 多列编辑

    webStorm可以像Sublime一样使用列编辑,只是区别在于webStorm只可以编辑连续列表. 按住alt键鼠标选择一列,然后输入文字就会编辑多行,这个功能很赞,比较实用(按住ALT键选中之后, ...

  2. 【Python】用Python打开IE、谷歌等浏览器报错及解决办法

    以IE浏览器为例: 当Python Shell输入下面代码时: >>> # coding=utf-8 >>> from selenium import webdri ...

  3. redis数据迁移操作

    redis客户端连接命令,分别连接旧环境中的主从redis Src目录下./redis-cli -h IP -p PORT 使用info replication 命令找出主redis使用客户端命令连接 ...

  4. 2_Jsp标签_传统标签功能简介

    1传统标签接口关系:                                   2功能简介                                                   ...

  5. mac os x升级MOUNTAIN LION后svn command not found的解决

    因为svn是个开发工具 所以苹果把他移到 Xcode developer package 里 去了,所以你没装xcode之类的,先去AppStore把xcode装了   装好之后sudo vi /et ...

  6. python 基础 7.4 os 模块

    #/usr/bin/python #coding=utf8 #@Time   :2017/11/11 3:15 #@Auther :liuzhenchuan #@File   :os 模块.py im ...

  7. 50道JAVA基础编程练习题 - 题目

    50道JAVA基础编程练习题[1]题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? [2]题目:判断 ...

  8. 【题解】CF359B Permutation

    [题解]CF359B Permutation 求一个长度为\(2n\)的序列,满足\(\Sigma |a_{2i}-a_{2i-1}|-|\Sigma a_{2i}-a_{2i-1}|=2k\) 这种 ...

  9. CentOS7的yum安装mysql

    CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 $ wget http://repo.mysql.com ...

  10. GIT笔记:将项目发布到码云

    GIT笔记:将项目发布到码云 发布步骤 1.码云创建项目 记录下项目的远程地址: https://gitee.com/mrsaber/ms_supplyAndSale.git 2.在本地创建GIT仓库 ...