oracle 11g goldengate搭建(一)
初学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搭建(一)的更多相关文章
- Oracle 11g DataGuard搭建(一) - 单节点到单节点
(一)DataGuard概要 DataGuard中文称为”数据卫士“,提供了数据库高可用性.数据保护和灾难恢复的功能.DataGuard通过建立primary数据库和standby数据库来确立参照关系 ...
- 搭建一个Oracle到Oracle的Goldengate双向复制环境
目标:搭建一个Oracle到Oracle的Goldengate双向复制环境(支持DDL+DML). 环境: OS:Red Hat Enterprise Linux Server release 5.5 ...
- 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 ...
- 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 ...
- 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] ...
- 基于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 ...
- 在win7系统上搭建django+oracle 11g时,注意事项
在win7系统上搭建django+oracle 11g时,注意事项[示例用的是python 2.7]: 重要:python.oracle.oracle client这三个的OS bit 一定一定要相同 ...
- VMware搭建Oracle 11g RAC测试环境 For Linux
环境如下: Linux操作系统:Centos 6.5 64bit (这个版本的redhat 6内核等OS在安装grid最后执行root.sh时会出现crs-4124,是oracle11.2.0.1的b ...
- 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: ...
随机推荐
- [K8s]无yaml文件重启Pod
在没有pod 的yaml文件时,强制重启某个pod kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f ...
- leetcode No.242 有效的字母异位词 valid-anagram (Python3实现)
题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词. 示例 1: 输入: s = "anagram", t = "nagaram&q ...
- Qt开发经验小技巧61-70
很多人问Qt嵌入式平台用哪个好,这里统一回答(当前时间节点2018年):imx6+335x比较稳定,性能高就用RK3288 RK3399,便宜的话就用全志H3,玩一玩可以用树莓派香橙派. 对于大段的注 ...
- Egret自定义位图文字(自定义+BitmapLabel)
一 自定位图文字 因为egret的位图文字是texturemerger做的,需要多张单图片导入tm,然后导出两个文件来使用,过程比较麻烦. 而Laya的位图文字则是一张整图数字图片,使用FontCli ...
- linux下 tab键失效 -bash: !ref: 为绑定变量
报错现象: Linux环境下,按Tab键进行补全时出现上图情况. [root@worker2 cjj]# vim /et-bash: !ref: 为绑定变量 -bash: !ref: 为绑定变量 -b ...
- CKA认证简介
- go 调度机制简介
goroutine是go中最重要的功能之一,正是因为有了goroutine这样强大的工具,go在并发方面表现的特别优秀. 那么goroutine和普通的线程和协程有什么区别呢?首先,我们需要明白线程和 ...
- tracking.js实现前端人脸识别
1.下载https://trackingjs.com/ 2.运行例子 纳总一下 发现效果 里面的代码为 <!doctype html><html><head> &l ...
- 领域模型/DDD领域驱动设计
http://www.fanyilun.me/2018/04/08/%E8%B0%88%E8%B0%88%E9%A2%86%E5%9F%9F%E5%BB%BA%E6%A8%A1/ http://www ...
- 【记录】【java】JDK8新特性Stream方式遍历集合
由于是以流方式,所以怎么操作也不改变原来的集合 1.普通遍历forEach List<String> list = new ArrayList(); list.add("a&qu ...