初学ogg,基本了解ogg原理及架构之后,趁热打铁,搭建一个简单的学习环境,以实现目标:将sourcedb数据库的2个表:sourceuser.test01和sourceuser.dept通过ogg分别同步到targetdb数据库的targetuser.test01和targetuser.dept表中,要求实现DML(insert、update、delete)同步。

基础环境

  源端 目标端  
操作系统版本 redhat 6.7 redhat 6.7
数据库版本  11.2.0.4 11.2.0.4
ogg版本  Oracle GoldenGate 11.2.1.0.3 for Oracle 11g on Linux x86-64 Oracle GoldenGate 11.2.1.0.3 for Oracle 11g on Linux x86-64
数据库/实例名称  sourcedb/sourcedb targetdb/targetdb    

(一)解压软件(源端和目标端执行)

[oracle@source-node ogg]$ unzip -q V34339-01.zip
[oracle@source-node ogg]$ ls
fbo_ggs_Linux_x64_ora11g_64bit.tar       Oracle GoldenGate_11.2.1.0.3_README.txt
OGG_WinUnix_Rel_Notes_11.2.1.0.3.pdf     V34339-01.zip
Oracle_GoldenGate_11.2.1.0.3_README.doc

[oracle@source-node ogg]$ tar -xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

(二)配置环境变量
[oracle@source-node ~]$ vim .bash_profile

export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH:$GG_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export GG_HOME=/u01/app/ogg

alias  ggsci='cd $GG_HOME;ggsci'

(三)源端数据库配置
(3.1)开启归档
查看是否开启归档
SQL> archive log list
Database log mode           No Archive Mode
Automatic archival           Disabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     4
Current log sequence           6

SQL> alter system set log_archive_dest_1='LOCATION=/archlog';

System altered.

SQL> alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;

System altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  534462464 bytes
Fixed Size            2254952 bytes
Variable Size          390072216 bytes
Database Buffers      134217728 bytes
Redo Buffers            7917568 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open ;

Database altered.

(3.2)打开强制生成日志
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.3)打开附加日志
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;

SUPPLEME
--------
NO

SQL>
SQL>
SQL> alter database add supplemental log data;

Database altered.

SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;

SUPPLEME
--------
YES

(3.4)修改goldengate参数
SQL> show parameter golden

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication         boolean     FALSE
SQL> alter system set enable_goldengate_replication=true;

System altered.

SQL> show parameter golden

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
enable_goldengate_replication         boolean     TRUE

(3.5)创建goldengat用户
创建专属表空间:
create tablespace tbs_ogg datafile '/u01/app/oracle/product/11.2.0/db_1/dbs/sourcedb/tbs_ogg01.dbf' size 100m autoextend on next 10m maxsize 30g;

创建用户:
create user ogg identified by ogg default tablespace tbs_ogg;

授予权限:
grant resource to ogg;
grant create session,alter session to ogg;
grant select any dictionary to ogg;
grant flashback any table to ogg;
grant alter any table to ogg;
grant select any table to ogg;
grant execute on dbms_flashback to ogg;
 
(3.6)创建测试用户及数据
create user sourceuser identified by sourceuser;
grant connect,resource to sourceuser;

conn sourceuser/sourceuser

--创建表
create table test01 (id  number,name varchar2(20));
--增加主键
alter table test01 add primary key(id);
--插入测试数据
insert into test01 values(1,'lijiaman');
insert into test01 values(2,'xiaoming');
insert into test01 values(3,'xiaohua');

--创建表
create table dept (deptno number,dname varchar2(14),loc varchar2(13));
--增加主键
alter table dept add primary key(deptno);
--插入测试数据
insert into dept values(10,'ACCOUNTING','NEW YORK');
insert into dept values(20,'RESEARCH','DALLAS');
insert into dept values(30,'SALES','CHICAGO');
insert into dept values(40,'OPERATIONS','BOSTON');

(3.7)导出数据(使用数据泵)
step1:创建路径
$[/home/oracle] mkdir datapump
$[/home/oracle] sqlplus sys/passwd as sysdba
sql > create or replace DIRECTORY exp_dir as '/home/oracle/datapump'

step2:为导出数据的用户授权
SQL> GRANT READ,WRITE ON DIRECTORY exp_dir TO sourceuser;
SQL> GRANT DATAPUMP_EXP_FULL_DATABASE TO sourceuser;

step3:执行数据导出
$[/home/oracle/datapump]expdp sourceuser/sourceuser directory = exp_dir dumpfile = sourcedb_table.dmp logfile = sourcedb_table.log tables = sourceuser.test01,sourceuser.dept;

(四)目标端数据库配置
(4.1)创建goldengat用户
创建专属表空间:
create tablespace tbs_ogg datafile '/u01/app/oracle/product/11.2.0/db_1/dbs/targetdb/tbs_ogg01.dbf' size 100m autoextend on next 10m maxsize 30g;

创建用户:
create user ogg identified by ogg default tablespace tbs_ogg;

授予权限:
grant resource to ogg;
grant create session,alter session to ogg;
grant select any dictionary to ogg;
grant flashback any table to ogg;
grant alter any table to ogg;
grant select any table to ogg;
grant execute on dbms_flashback to ogg;
grant insert any table to ogg;
grant update any table to ogg;
grant delete any table to ogg;

(4.2)创建测试用户
create user targetuser identified by targetuser;
grant connect,resource to targetuser;

(4.3)导入源端已经导出的数据(初始化数据)
step1:创建路径
$[/home/oracle] mkdir datapump
$[/home/oracle] sqlplus sys/passwd as sysdba
sql > create or replace DIRECTORY imp_dir as '/home/oracle/datapump';

(2)为导入数据的用户授权
SQL> GRANT READ,WRITE ON DIRECTORY imp_dir TO targetuser;
SQL> GRANT DATAPUMP_IMP_FULL_DATABASE TO targetuser;

(3)将文件拷贝过来(在源端执行)
cd /home/oracle/datapump
scp sourcedb_table.dmp oracle@192.168.10.12:/home/oracle/datapump

(4)执行导入
$[/home/oracle/datapump]impdp targetuser/targetuser directory=imp_dir dumpfile =sourcedb_table.dmp  remap_schema=sourceuser:targetuser;

(五)源端ogg配置
(5.1)创建ogg相关目录
[oracle@source-node ~]$ cd $GG_HOME
[oracle@source-node ogg]$ ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.

GGSCI (source-node) 1> create subdirs

Creating subdirectories under current directory /u01/app/ogg

Parameter files                /u01/app/ogg/dirprm: already exists
Report files                   /u01/app/ogg/dirrpt: created
Checkpoint files               /u01/app/ogg/dirchk: created
Process status files           /u01/app/ogg/dirpcs: created
SQL script files               /u01/app/ogg/dirsql: created
Database definitions files     /u01/app/ogg/dirdef: created
Extract data files             /u01/app/ogg/dirdat: created
Temporary files                /u01/app/ogg/dirtmp: created
Stdout files                   /u01/app/ogg/dirout: created

(5.2)配置并启动mgr进程
GGSCI (source-node) 2> edit param mgr
port 7809
dynamicportlist 7840-7845

GGSCI (source-node) 3> start mgr
Manager started.

GGSCI (source-node) 4> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING

(5.3)开启待同步表的额外日志
GGSCI (source-node) 6> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (source-node) 7> add trandata sourceuser.test01
Logging of supplemental redo data enabled for table SOURCEUSER.TEST01.

GGSCI (source-node) 10> add trandata sourceuser.dept
Logging of supplemental redo data enabled for table SOURCEUSER.DEPT.

(5.4)配置抽取进程exta
GGSCI (source-node) 11> add extract exta,tranlog,begin now
EXTRACT added.

GGSCI (source-node) 12> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          
EXTRACT     STOPPED     EXTA        00:00:00      00:00:05

GGSCI (source-node) 13> add exttrail ./dirdat/ra,extract exta
EXTTRAIL added.

GGSCI (source-node) 14> edit param exta
extract exta
userid ogg,password ogg
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
exttrail ./dirdat/ra
dynamicresolution
gettruncates
table sourceuser.test01;
table sourceuser.dept;

GGSCI (source-node) 16> start exta

Sending START request to MANAGER ...
EXTRACT EXTA starting

GGSCI (source-node) 17> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          
EXTRACT     RUNNING     EXTA        00:07:51      00:00:05

(5.5)配置投递进程

GGSCI (source-node) 21> add extract dpa,exttrailsource ./dirdat/ra
EXTRACT added.

GGSCI (source-node) 22> edit param dpa

extract dpa
userid ogg,password ogg
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
passthru
rmthost 192.168.10.12,mgrport 7809
rmttrail ./dirdat/ra
table sourceuser.test01;
table sourceuser.dept;

GGSCI (source-node) 23> add rmttrail ./dirdat/ra,extract dpa
RMTTRAIL added.

GGSCI (source-node) 26> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                          
EXTRACT     RUNNING     DPA         00:00:00      00:03:46   
EXTRACT     RUNNING     EXTA        00:00:00      00:00:05

(六)目标端ogg配置
(6.1)创建ogg相关目录
[oracle@target-node ~]$ cd $GG_HOME

[oracle@target-node ogg]$ ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21

Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.

GGSCI (target-node) 1> create subdirs

Creating subdirectories under current directory /u01/app/ogg

Parameter files                /u01/app/ogg/dirprm: already exists
Report files                   /u01/app/ogg/dirrpt: created
Checkpoint files               /u01/app/ogg/dirchk: created
Process status files           /u01/app/ogg/dirpcs: created
SQL script files               /u01/app/ogg/dirsql: created
Database definitions files     /u01/app/ogg/dirdef: created
Extract data files             /u01/app/ogg/dirdat: created
Temporary files                /u01/app/ogg/dirtmp: created
Stdout files                   /u01/app/ogg/dirout: created

(6.2)配置并启动mgr进程
GGSCI (target-node) 2> edit param mgr
port 7809
dynamicportlist 7840-7845

GGSCI (target-node) 3> start mgr
Manager started.

GGSCI (target-node) 4> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING

(6.3)配置ogg检查点
GGSCI (target-node) 5> edit param ./globals
checkpointtable ogg.checkpoint

GGSCI (target-node) 6> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (target-node) 7> add checkpointtable ogg.checkpoint

Successfully created checkpoint table ogg.checkpoint.

(6.4)配置复制进程
GGSCI (target-node) 14> add replicat repa,exttrail ./dirdat/ra,checkpointtable ogg.checkpoint
REPLICAT added.

GGSCI (target-node) 36> edit param repa

replicat repa
setenv (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg,password ogg
numfiles 500
grouptransops 10000
handlecollisions
assumetargetdefs
allownoopupdates
dynamicresolution
discardfile ./dirrpt/repa_discard.txt,append,megabytes 10
map sourceuser.*,target targetuser.*;

GGSCI (target-node) 17> start repa
Sending START request to MANAGER ...
REPLICAT REPA starting

GGSCI (target-node) 18> info all
Program     Status      Group       Lag at Chkpt  Time Since Chkpt
MANAGER     RUNNING                                          
REPLICAT    RUNNING     REPA        00:00:00      00:00:02

(七)测试ogg复制功能
1.在sourceuser.test01表中插入数据,发现targetuser.test01中有新数据进入;
2.在源端执行delete from test01并提交,目标端targetuser.test01中的数据也全部删除;
3.对源表非主键列进行update操作:update dept set loc='sichuan' where deptno=40,目标端也自动更新;
4.对源表主键列进行update操作:update dept set deptno=deptno+1,目标端也自动更新;

【完】

oracle 11g goldengate搭建(一)的更多相关文章

  1. Oracle 11g DataGuard搭建(一) - 单节点到单节点

    (一)DataGuard概要 DataGuard中文称为”数据卫士“,提供了数据库高可用性.数据保护和灾难恢复的功能.DataGuard通过建立primary数据库和standby数据库来确立参照关系 ...

  2. 搭建一个Oracle到Oracle的Goldengate双向复制环境

    目标:搭建一个Oracle到Oracle的Goldengate双向复制环境(支持DDL+DML). 环境: OS:Red Hat Enterprise Linux Server release 5.5 ...

  3. Oracle GoldenGate for Oracle 11g to PostgreSQL 9.2.4 Configuration

    Installing and setting up Oracle GoldenGate connecting to an Oracle database Also please make sure t ...

  4. Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 3

    DDL Setup Steps SQL> grant execute on utl_file to ggs; Grant succeeded. Create GLOBALS file [orac ...

  5. Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 4

    Target Side Setup Install OGG on Target Side Creates required directories for OGG [oracle@vzwc1 ggs] ...

  6. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.7.Oracle 11G R2 RAC修改public网络IP

    问题:Linuxrac2节点的public网IP被占用,导致集群节点2无法访问 1.禁止相关CRS资源的启动,停止这些资源(vip,listener,scan,scan_listener,databa ...

  7. 在win7系统上搭建django+oracle 11g时,注意事项

    在win7系统上搭建django+oracle 11g时,注意事项[示例用的是python 2.7]: 重要:python.oracle.oracle client这三个的OS bit 一定一定要相同 ...

  8. VMware搭建Oracle 11g RAC测试环境 For Linux

    环境如下: Linux操作系统:Centos 6.5 64bit (这个版本的redhat 6内核等OS在安装grid最后执行root.sh时会出现crs-4124,是oracle11.2.0.1的b ...

  9. Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 1

    Source Database DB Name:        zwc Schemas:         HR,OE,PM Version:          10.2.0.4 RAC:       ...

随机推荐

  1. ES技巧

    2, 统计字段b的不同值的数量 {"size":0,"aggs":{"distinct_colors":{"cardinality ...

  2. 连接池-Mybatis源码

    持续更新:https://github.com/dchack/Mybatis-source-code-learn Mybatis连接池 有这么个定律,有连接的地方就有池. 在市面上,可以适配Mybat ...

  3. shell基础知识之数组

    数组允许脚本利用索引将数据集合保存为独立的条目.Bash支持普通数组和关联数组,前者 使用整数作为数组索引,后者使用字符串作为数组索引.当数据以数字顺序组织的时候,应该使 用普通数组,例如一组连续的迭 ...

  4. iOS - 在xib中UILabel文字如何换行

    在换行的位置按住Option + Enter键即可换行

  5. c#的BeginInvoke和EndInvoke使用demo

    BeginInvoke方法可以使用线程异步地执行委托所指向的方法.然后通过EndInvoke方法获得方法的返回值(EndInvoke方法的返回值就是被调用方法的返回值),或是确定方法已经被成功调用. ...

  6. javascript Round Function

    var rounded = Math.round( number * 10 ) / 10; // round to one digit var rounded = Math.round( number ...

  7. RabbitMQ使用及与spring boot整合

    1.MQ 消息队列(Message Queue,简称MQ)——应用程序和应用程序之间的通信方法 应用:不同进程Process/线程Thread之间通信 比较流行的中间件: ActiveMQ Rabbi ...

  8. laravel jwt实践

    laravel版本为5.5 1.使用 composer 安装 composer require tymon/jwt-auth 1.*@rc 2.发布配置文件 # 这条命令会在 config 下增加一个 ...

  9. Docker下安装zookeeper(单机 & 集群)

    启动Docker后,先看一下我们有哪些选择. 有官方的当然选择官方啦~ 下载: [root@localhost admin]# docker pull zookeeper Using default ...

  10. SpringBoot整合websocket

    1.新增pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...