OGG学习笔记02
实验环境:
源端:192.168.1.30,Oracle 10.2.0.5 单实例
目标端:192.168.1.31,Oracle 10.2.0.5 单实例
1.模拟源数据库业务持续运行
OGG的单向配置比较简单,但实际生产过程很多业务要求不间断运行,
所以我创建了2张模拟业务表,简单模拟在业务不间断运行场景下OGG的配置。
1.1 创建模拟的业务用户
首先我创建业务用户jy,并指定密码,赋予基本业务用户的角色权限。
--user
create user jy identified by jy default tablespace users;
--grant
grant resource, connect to jy;
1.2 在业务用户下创建表和存储过程
连接到业务用户jy下,创建1个序列,2张表(其中一张表有主键):
--connect
conn jy/jy
--sequence
create sequence s1;
--tables
--table t_second 无主键
create table t_second as select s1.nextval id, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') time from dual;
--table t_second_p 有主键
create table t_second_p as select s1.nextval id, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') time from dual;
alter table t_second_p add constraint pk_t_second_p primary key(id);
创建存储过程,功能是:每秒向2张业务表分别插入1条数据;
用来模拟持续运行的业务;
--procedure
create or replace procedure p1 is
begin
for i in 1..86400
loop
insert into t_second select s1.nextval, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
commit;
insert into t_second_p select s1.nextval, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
commit;
dbms_lock.sleep(1);
end loop;
end;
/
执行存储过程,相当于模拟业务正式启动:
--execute
[oracle@oradb30 scripts]$ cat business.sh
#!/bin/bash
sqlplus jy/jy <<EOF
exec p1;
EOF
[oracle@oradb30 scripts]$ nohup sh business.sh &
2.配置OGG前期准备
2.1 创建源端和目标端OGG的管理员用户
--源数据库端:
create user ggs_admin identified by ggs_admin;
grant dba to ggs_admin;
--目标数据库端:
create user ggt_admin identified by ggt_admin;
grant dba to ggt_admin;
2.2 配置源数据库端的附加日志
--查看数据库附加日志开启状态:
SQL> select SUPPLEMENTAL_LOG_DATA_MIN, SUPPLEMENTAL_LOG_DATA_PK,
SUPPLEMENTAL_LOG_DATA_UI from v$database;
--数据库级别开启最小附加日志:
SQL> alter database add supplemental log data;
--表级别开启详细附加日志:
GGSCI (oradb30) 6> dblogin userid ggs_admin@ora10, password ggs_admin
Successfully logged into database.
GGSCI (oradb30) 7> add trandata jy.t_second
2017-01-13 23:37:38 WARNING OGG-00869 No unique key is defined for table 'T_SECOND'. 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 JY.T_SECOND.
GGSCI (oradb30) 8> add trandata jy.t_second_p
Logging of supplemental redo data enabled for table JY.T_SECOND_P.
GGSCI (oradb30) 9>
2.3 配置源端和目标端的OGG所需进程
配置进程(组)名没有具体的规范,我这里参考晓明在书中所用的组命名方式:
对于复杂环境,第一位字母,local、immdiate、remote 分别对应 l、i、r;
后面根据进程属性属于extract、datapump、replicat 而分别对应 x、p、r;
源端:
源端在上篇已经配置好Manager进程。
接下来继续配置源端的extract进程:
GGSCI (oradb30) 3> edit params lxjy1
--Local Extract lxjy1
--Author: Alfred Zhao
--
EXTRACT lxjy1
SETENV(NLS_LANG=american_america.ZHS16GBK)
SETENV(ORACLE_SID=ora10)
USERID ggs_admin, PASSWORD ggs_admin
EXTTRAIL ./dirdat/sa
TABLE JY.T_SECOND;
TABLE JY.T_SECOND_P;
添加lxjy1进程(local extract):
GGSCI (oradb30) 1> add extract lxjy1, tranlog, begin now, threads 1
EXTRACT added.
GGSCI (oradb30) 2> add exttrail ./dirdat/sa, extract lxjy1, megabytes 50
EXTTRAIL added.
配置源端的datapump进程:
--Local datapump lpjy1
--Author: Alfred Zhao
--
EXTRACT lpjy1
PASSTHRU
RMTHOST 192.168.1.31, MGRPORT 7777
RMTTRAIL ./dirdat/ta
TABLE JY.T_SECOND;
TABLE JY.T_SECOND_P;
添加lpjy1进程(本地datapump进程):
GGSCI (oradb30) 2> add extract lpjy1, exttrailsource ./dirdat/sa, begin now
EXTRACT added.
GGSCI (oradb30) 17> ADD RMTTRAIL ./dirdat/ta, EXTRACT LPJY1, MEGABYTES 50
RMTTRAIL added.
查看目前源端进程状态:
GGSCI (oradb30) 7> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED LPJY1 00:00:00 00:07:01
EXTRACT STOPPED LXJY1 00:00:00 00:18:55
可以看到Manager进程启动,LXJY1和LPJY1没有启动。
目标端:
参考《OGG学习笔记01-基础概述》中安装配置,对目标端也配置Manager进程。
配置checkpointtable:
GGSCI (oradb31) 1> view params ./GLOBALS
checkpointtable ggt_admin.chkpt
GGSCI (oradb31) 2> dblogin userid ggt_admin@ora10dg, password ggt_admin
Successfully logged into database.
GGSCI (oradb31) 3> add checkpointtable
No checkpoint table specified, using GLOBALS specification (ggt_admin.chkpt)...
Successfully created checkpoint table ggt_admin.chkpt.
然后继续配置replicat进程:
--replicat rjy1
--Author: Alfred Zhao
--
REPLICAT rjy1
SETENV (ORACLE_SID=ora10)
USERID ggt_admin, PASSWORD ggt_admin
DISCARDFILE ./dirrpt/rjy1.dsc, PURGE
HandleCollisions
AssumeTargetDefs
Map jy.*,Target jy.*;
添加rjy1进程(replicat进程):
GGSCI (oradb31) 8> add replicat rjy1, exttrail ./dirdat/ta
REPLICAT added.
查看当前目标端进程状态:
GGSCI (oradb31) 9> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT STOPPED RJY1 00:00:00 00:00:18
可以看到Manager已经启动,RJY1还没有启动。
3.配置OGG单向复制
注意以下3个步骤执行的顺序不能更改,否则很可能会造成数据不一致。
3.1 启动源库extract进程
确认已经启动Manager进程。
启动lxjy1
GGSCI (oradb30) 12> start extract lxjy1
启动lpjy1
GGSCI (oradb30) 19> start extract lpjy1
查看源端进程状态:
GGSCI (oradb30) 20> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING LPJY1 01:08:28 00:00:00
EXTRACT RUNNING LXJY1 00:00:00 00:00:10
可以看到所有进程都是正常RUNNING状态。如果启动后状态不是RUNNING,就需要检查配置和查看 ggserr.log 日志信息定位原因。
现在可以查看源端extract进程信息:
GGSCI (oradb30) 21> info extract lxjy1
EXTRACT LXJY1 Last Started 2017-01-14 00:57 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:03 ago)
Log Read Checkpoint Oracle Redo Logs
2017-01-14 01:05:56 Thread 1, Seqno 133, RBA 41481856
SCN 0.1517654 (1517654)
GGSCI (oradb30) 22> info extract lpjy1
EXTRACT LPJY1 Last Started 2017-01-14 01:02 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:09 ago)
Log Read Checkpoint File ./dirdat/sa000000
2017-01-14 01:06:00.000000 RBA 1551197
可以看到OGG的extract进程抓取到的信息:
GGSCI (oradb30) 26> STATS ext lxjy1
Sending STATS request to EXTRACT LXJY1 ...
Start of Statistics at 2017-01-14 01:09:21.
Output to ./dirdat/sa:
Extracting from JY.T_SECOND to JY.T_SECOND:
*** Total statistics since 2017-01-14 00:58:01 ***
Total inserts 5217.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 5217.00
*** Daily statistics since 2017-01-14 00:58:01 ***
Total inserts 5217.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 5217.00
*** Hourly statistics since 2017-01-14 01:00:00 ***
Total inserts 560.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 560.00
*** Latest statistics since 2017-01-14 00:58:01 ***
Total inserts 5217.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 5217.00
Extracting from JY.T_SECOND_P to JY.T_SECOND_P:
*** Total statistics since 2017-01-14 00:58:01 ***
Total inserts 5217.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 5217.00
*** Daily statistics since 2017-01-14 00:58:01 ***
Total inserts 5217.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 5217.00
*** Hourly statistics since 2017-01-14 01:00:00 ***
Total inserts 560.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 560.00
*** Latest statistics since 2017-01-14 00:58:01 ***
Total inserts 5217.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 5217.00
End of Statistics.
GGSCI (oradb30) 27> stats ext lpjy1
Sending STATS request to EXTRACT LPJY1 ...
Start of Statistics at 2017-01-14 01:09:31.
Output to ./dirdat/ta:
Extracting from JY.T_SECOND to JY.T_SECOND:
*** Total statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
*** Daily statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
*** Hourly statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
*** Latest statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
Extracting from JY.T_SECOND_P to JY.T_SECOND_P:
*** Total statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
*** Daily statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
*** Hourly statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
*** Latest statistics since 2017-01-14 01:02:43 ***
Total inserts 4509.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 4509.00
End of Statistics.
GGSCI (oradb30) 28>
3.2 初始化目标库数据
我这里使用Oracle的exp/imp工具,从源端导出数据,导入到目标端。
exp 导出源库表数据
--exp 导出
exp jy/jy tables=t_second,t_second_p file=source_jy.dmp log=exp_source_jy.log
SQL> select count(1) from t_second;
COUNT(1)
----------
11056
SQL> select count(1) from t_second_p;
COUNT(1)
----------
11072
[oracle@oradb30 ~]$ exp jy/jy tables=t_second,t_second_p file=source_jy.dmp log=exp_source_jy.log
Export: Release 10.2.0.5.0 - Production on Sat Jan 14 01:15:26 2017
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 0g Enterprise Edition Release 10.2.0.5.0 - 4bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table T_SECOND 11096 rows exported
EXP-00091: Exporting questionable statistics.
. . exporting table T_SECOND_P 11097 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
imp 导入目标库数据
--创建用户
create user jy identified by jy default tablespace users;
grant resource, connect to jy;
--imp 导入
imp jy/jy tables=t_second,t_second_p file=source_jy.dmp log=imp_source_jy.log
[oracle@oradb31 ~]$ imp jy/jy tables=t_second,t_second_p file=source_jy.dmp log=imp_source_jy.log
Import: Release 10.2.0.5.0 - Production on Sat Jan 14 01:20:08 2017
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. importing JY's objects into JY
. importing JY's objects into JY
. . importing table "T_SECOND" 11096 rows imported
. . importing table "T_SECOND_P" 11097 rows imported
Import terminated successfully without warnings.
3.3 开启目标库replicat应用
确认已经启动Manager进程。
启动replicat应用
GGSCI (oradb31) 2> start replicat rjy1
Sending START request to MANAGER ...
REPLICAT RJY1 starting
GGSCI (oradb31) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING RJY1 00:00:00 00:41:50
下面我来验证数据:
--开启replicat之前查询目标库,也就是初始化导入的数据:
SQL> select count(1) from t_second;
COUNT(1)
----------
11096
SQL> select count(1) from t_second_p;
COUNT(1)
----------
11097
--开启replicat后查询目标库:
SQL> select count(1) from t_second_p;
COUNT(1)
----------
11581
SQL> select count(1) from t_second;
COUNT(1)
----------
16459
为了更清晰的看到差异,我将模拟应用的会话杀掉,这样两表的数量不再变化。
--查询源库两个表的数量:
SQL> select count(1) from t_second_p;
COUNT(1)
----------
11966
SQL> select count(1) from t_second;
COUNT(1)
----------
11966
--查看目标库两个表的数量:
SQL> select count(1) from t_second_p;
COUNT(1)
----------
11966
SQL> select count(1) from t_second;
COUNT(1)
----------
16840
发现有主键的表t_second_p在ogg同步后数据完全一致,符合预期;
而没有主键的表t_second在ogg同步后数据重复插入了一部分(即源端开启extract进程后捕获到的插入,和imp导入成功前这期间的数据重复插入了)
根据这个现象,OGG需要同步的表还是最好有主键约束。
最后,一切正常后,把目标端replicat进程的参数文件中的HandleCollisions配置去掉。因为正式同步后是建议有冲突问题人工处理。
Reference
- 张晓明. 大话Oracle Grid[M]. 人民邮电出版社, 2014.
- Oracle GoldenGate 11g Implementer's guide
OGG学习笔记02的更多相关文章
- OGG学习笔记02-单向复制配置实例
OGG学习笔记02-单向复制配置实例 实验环境: 源端:192.168.1.30,Oracle 10.2.0.5 单实例 目标端:192.168.1.31,Oracle 10.2.0.5 单实例 1. ...
- 软件测试之loadrunner学习笔记-02集合点
loadrunner学习笔记-02集合点 集合点函数可以帮助我们生成有效可控的并发操作.虽然在Controller中多用户负载的Vuser是一起开始运行脚本的,但是由于计算机的串行处理机制,脚本的运行 ...
- OGG学习笔记01-基础概述
OGG学习笔记01-基础概述 OGG(Oracle Golden Gate),最近几年在数据同步.容灾领域特别火,甚至比Oracle自己的原生产品DataGuard还要风光,主要是因为其跨平台.跨数据 ...
- OGG学习笔记03-单向复制简单故障处理
OGG学习笔记03-单向复制简单故障处理 环境:参考:OGG学习笔记02-单向复制配置实例 实验目的:了解OGG简单故障的基本处理思路. 1. 故障现象 故障现象:启动OGG源端的extract进程, ...
- OGG学习笔记04-OGG复制部署快速参考
OGG学习笔记04-OGG复制部署快速参考 源端:Oracle 10.2.0.5 RAC + ASM 节点1 Public IP地址:192.168.1.27 目标端:Oracle 10.2.0.5 ...
- OGG学习笔记05-OGG的版本
刚接触OGG的时候,很容易被众多的版本搞晕,虽然官方有提供各版本对应认证OS和DB的表格. 个人认为一个比较简单的方式,是直接去edelivery.oracle.com下载OGG,选定一个大版本后,这 ...
- 机器学习实战(Machine Learning in Action)学习笔记————02.k-邻近算法(KNN)
机器学习实战(Machine Learning in Action)学习笔记————02.k-邻近算法(KNN) 关键字:邻近算法(kNN: k Nearest Neighbors).python.源 ...
- OpenCV 学习笔记 02 使用opencv处理图像
1 不同色彩空间的转换 opencv 中有数百种关于不同色彩空间的转换方法,但常用的有三种色彩空间:灰度.BRG.HSV(Hue-Saturation-Value) 灰度 - 灰度色彩空间是通过去除彩 ...
- OGG学习笔记01
OGG学习笔记01-基础概述OGG(Oracle Golden Gate),最近几年在数据同步.容灾领域特别火,甚至比Oracle自己的原生产品DataGuard还要风光,主要是因为其跨平台.跨数据库 ...
随机推荐
- TelephonyUtils
<uses-permission android:name="android.permission.CALL_PHONE"/> import java.util.Arr ...
- rally测试opentack------安装部署和简单实践
1,下载 git clone git://git.openstack.org/openstack/rally 或者 git clone https://git.openstack.org/openst ...
- 【JVM学习笔记】扩展类加载器
扩展类加载器独有的特点,代码如下 public class Sample { } public class Test { static { System.out.println("Test ...
- Python 常用模块(1) -- collections模块,time模块,random模块,os模块,sys模块
主要内容: 一. 模块的简单认识 二. collections模块 三. time时间模块 四. random模块 五. os模块 六. sys模块 一. 模块的简单认识 模块: 模块就是把装有特定功 ...
- Docker知识点总结
一. docker介绍: 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不 ...
- 安装nova
在控制节点上执行 controllerHost='controller' controllerIP='172.31.240.49' MYSQL_PASSWD='m4r!adbOP' RABBIT_PA ...
- web题-自己做的
@sqlmap工具注入 sql基础教程https://jingyan.baidu.com/article/eae078276530621fec5485b9.html 最后啥都有了查询flag表的fla ...
- Similar String Groups
Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it ...
- Spring4学习回顾之路07- 通过工厂方法配置Bean
一:通过静态工厂配置Bean 建立Student.java package com.lql.srping04; /** * @author: lql * @date: 2019.10.28 * Des ...
- #undef取消宏定义
如果你想定义这个宏那就#define X 如果你不想让你已经#define X的宏在其他地方由于引入这个包含宏定义的.h文件而引起一些编译问题,那你就#undef X掉,就这么简单. 举个简单的例子: ...