二、配置和使用
阅读导航
配置和使用GoldenGate的步骤
1 配置数据库支持GoldenGate
1.1 OGG用户和权限分配
1.2 数据库附加日志
1.2.1 数据库级别的附加日志
1.2.2 用户级别的附加日志
1.2.3 表级别的附加日志
2 配置GoldenGate
2.1 GoldenGate MGR进程
2.1.1 配置GoldenGate MGR进程
2.1.2 启动mgr进程
2.2 在源端创建和配置Extract进程
2.2.1 创建主抽取进程(Primary Extract)
2.2.1.1 配置主抽取进程(Primary Extract)参数
2.2.2 创建和配置Data Pump进程(Secondly Extract)
2.2.2.1 创建Data Pump Extract进程
2.2.2.2 配置Data Pump Extract进程
2.2.2.3 将目标端trail文件添加到队列中
2.3 在目标端配置Replicat
2.3.1 创建和配置Checkpoint Table
2.3.2 创建和配置Replicat进程
3 初始化数据
4 使用GoldenGate
5 总结
配置和使用GoldenGate的步骤
1 在源端和目标端配置数据库支持GoldenGate
2 在源端和目标端创建和配置GoldenGate实例
3 在源端创建和配置主抽取进程(Primary Extract)
4 在源端创建和配置Data Pump进程(Secondly Extract)
5 在目标端创建和配置Replicat进程
1 配置数据库支持GoldenGate
1.1 OGG用户和权限分配
GoldenGate需要从在线日子或归档日志抽取捕获系统的变更数据信息,这些信息可能来源于业务用户,可能来源于系统用户,为了使
GoldenGate能够抽取这些数据应为GoldenGate创建独立的用户和分配必要的权限以满足系统运行需求,这些权限包括读取业务用户表数据的权
限、读取系统表的权限、执行某个系统包的权限等,以下脚步创建GoldenGate用户ogg_owner(源用户)、ogg_trg(目标用户)和
GoldenGate角色ogg_role:
[@sywu ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Aug 21 14:11:04 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SYS@sydb>create tablespace tbs01
datafile '+oradata'
size 10m
autoextend on
uniform size 2m
/
create user ogg_owner identified by ogg_owner default tablespace tbs01 quota unlimited on tbs01
/
create user ogg_trg identified by ogg_trg default tablespace tbs01 quota unlimited on tbs01
/
create role ogg_role
/
为易管理和维护统一将权限赋予角色ogg_role:
grant
CREATE SESSION,
ALTER SESSION,
ALTER SYSTEM,
RESOURCE,
SELECT ANY DICTIONARY,
FLASHBACK ANY TABLE,
SELECT ANY TABLE,
SELECT ANY TRANSACTION,
insert any table,
update any table,
drop any table,
CREATE TABLE
to ogg_role;
grant SELECT on dba_clusters to ogg_role;
grant SELECT on V_$DATABASE to ogg_role;
grant select on sys.logmnr_buildlog to ogg_role;
grant EXECUTE on DBMS_FLASHBACK to ogg_role;
grant execute on DBMS_CAPTURE_ADM to ogg_role;
grant execute on DBMS_STREAMS to ogg_role;
grant EXECUTE_CATALOG_ROLE to ogg_role;
然后再将ogg_role 角色赋予ogg_owner(源用户)和ogg_trg(目标用户):
grant ogg_role to ogg_owner;
grant ogg_role to ogg_trg;
源用户测试表和数据:
SYS@sydb>create table ogg_owner.togg(id primary key,name,type,CREATED,update_date)
2 as
3 select object_id,object_name,object_type,CREATED,sysdate from dba_objects
4 where rownum<1001 5 / Table created. Elapsed: 00:00:00.28
1.2 数据库附加日志
附加日志级别分为:
数据库级别的附加日志(必须附加日志)
用户级别的附加日志(当使用GoldenGate DDL抽取功能时要启用该级别)
表级别的附加日志(必须附加日志,除非你启用了用户级别的附加日志)
1.2.1 数据库级别的附加日志
因为GoldenGate需要抽取捕获变更数据信息和元数据信息,这些信息需要记录日志,并且因为日志总是持续增长的,这些日志增长的信息对于GoldenGate是必须记录的,所以必须在GoldenGate进程启动前开启数据库级别的附加日志;
检查数据库是否开启附加日志:
SYS@sydb>SELECT supplemental_log_data_min, force_logging FROM v$database;
SUPPLEME FOR
-------- ---
NO NO
开启数据库级别的附加日志:
SYS@sydb>alter database add supplemental log data;
SYS@sydb>ALTER DATABASE FORCE LOGGING;
SYS@sydb>SELECT supplemental_log_data_min, force_logging FROM v$database;
SUPPLEME FOR
-------- ---
YES YES
Elapsed: 00:00:00.00
SYS@sydb>alter system switch logfile;
System altered.
Elapsed: 00:00:00.09
1.2.2 用户级别的附加日志
开启用户级别的附加日志的管理用户必须具有执行DBMS_CAPTURE_ADM包的权限;可以在GoldenGate GGSCI命令行下登录到数据库管理用户为其它的用户开启附加日志;
在GGSCI命令行下使用DBLOGIN命令登录到数据库管理用户
GGSCI (sywu) 1> dblogin userid ogg_owner,password ogg_owner
Successfully logged into database.
为用户启用附加日志
GGSCI (sywu as ogg_owner@sydb) 2> add schematrandata sywu
2015-08-24 14:56:26 INFO OGG-01788 SCHEMATRANDATA has been added on schema sywu.
2015-08-24 14:56:27 INFO OGG-01976 SCHEMATRANDATA for scheduling columns has been added on schema sywu.
取消用户附加日志
GGSCI (sywu as ogg_owner@sydb) 6> delete schematrandata sywu
2015-08-25 20:14:49 INFO OGG-01792 SCHEMATRANDATA has been deleted on schema sywu.
2015-08-25 20:14:49 INFO OGG-01979 SCHEMATRANDATA for scheduling columns has been deleted on schema sywu.
1.2.3 表级别的附加日志
在没有启用用户级别的附加日志的情况下表级别的主键或唯一索引附加日志对于GoldenGate是必须的;在某些情况下即使你启用了用户级别的
附加日志,你也可以启用表级别的附加日志使主键附加日志替代每一个在用户级别为GoldenGate指定的键;必须在表没有主键或唯一索引的情况下启用表
级别的附加日志。
在GGSCI命令行下使用dblogin登录到数据库管理用户
GGSCI (sywu) 1> dblogin userid ogg_owner,password ogg_owner
Successfully logged into database.
为表启用附加日志
GGSCI (sywu as ogg_owner@sydb) 3> add trandata ogg_owner.togg
Logging of supplemental redo data enabled for table OGG_OWNER.TOGG.
TRANDATA for scheduling columns has been added on table 'OGG_OWNER.TOGG'.
注意:仅当该表有主键或唯一索引时使用上面的命令启用表级别的附加日志,如果表中没有主键或唯一索引时则必须指定一个或多个或者全部列做为主键,在GoldenGate这些键的作用是过滤重复的数据。
SYS@sydb>create table ogg_owner.togg_nokey(id,name,type,CREATED,update_date)
2 as
3 select object_id,object_name,object_type,CREATED,sysdate from dba_objects
where rownum<1001 5 / Table created. Elapsed: 00:00:00.11
错误的启用没有主键的表级别附加日志:
GGSCI (sywu as ogg_owner@sydb) 4> add trandata ogg_owner.togg_nokey
2015-08-24 16:05:01 WARNING OGG-06439 No unique key is defined for table TOGG_NOKEY. 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 OGG_OWNER.TOGG_NOKEY.
TRANDATA for scheduling columns has been added on table 'OGG_OWNER.TOGG_NOKEY'.
正确的启用没有主键的表级别附加日志:
GGSCI (sywu as ogg_owner@sydb) 26> add trandata ogg_owner.togg_nokey,cols (ID),nokey
2015-08-24 16:33:19 WARNING OGG-06439 No unique key is defined for table TOGG_NOKEY. 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 OGG_OWNER.TOGG_NOKEY.
TRANDATA for scheduling columns has been added on table 'OGG_OWNER.TOGG_NOKEY'.
2 配置GoldenGate
2.1 GoldenGate MGR进程
MGR进程管理启动Oracle GoldenGate进程、启动动态进程、分配端口给GoldenGate进程、管理trail
file、创建事件,错误和诊断报告工作,必须在第一时间启动;当某些原因导致GoldenGate崩溃或重启机器时,默认情况MGR是没有启动的
[oracle@sywu ogg_src]$ tggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu) 1> info mgr
Manager is DOWN!
2.1.1 配置GoldenGate MGR进程
可以通过直接编辑GoldenGate_home/dirprm/mgr.prm文件或进入GGSCI命令行后键入edit param mgr命令回车进入MGR配置文件vi编辑界面;
GGSCI (sywu as ogg_owner@sydb) 10> edit param mgr
PORT 7809
DYNAMICPORTLIST 7810-7820
AUTOSTART ER E*
AUTORESTART ER P*,RETRIES 4, WAITMINUTES 4
STARTUPVALIDATIONDELAY 5
参数
说明
PORT
表示MGR进程端口号
DYNAMICPORTLIST
表示MGR进程动态为其它进程如Extract进程、Replicat进程分配的端口
AUTOSTART、AUTORESTART
表示当MGR进程启动后失败时自动启动或重启的GoldenGate进程
2.1.2 启动mgr进程
GGSCI (sywu) 2> start mgr
Manager started.
GGSCI (sywu) 3> info mgr
Manager is running (IP port sywu.7909, Process ID 17400).
启动原理:通过读取GoldenGate_home/dirprm/mgr.prm文件,然后根据该文件的配置信息启动进程分配端口号,如果该进程启动失败,首先请检查预使用的端口是否被占用:
netstat -lntup|grep 7809
tcp 0 0 :::7809 :::* LISTEN 32426/./mgr
然后检查相关的配置文件或重新配置MGR。
2.2 在源端创建和配置Extract进程
创建和配置Extract进程的工作有:
创建和配置主抽取进程(Primary Extract)
创建和配置Data Pump进程(Secondly Extract)
2.2.1 创建主抽取进程(Primary Extract)
进入GGSCI命令行使用add extract 命令创建主抽取进程
[oracle@sywu ~]$ sggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu as ogg_owner@sydb) 13> add extract esydb001,tranlog,begin now
EXTRACT added.
因为主进程的作用是抽取捕获系统变更数据并将这些数据保存到trail文件里,所以必须为其配置trail文件目录和trail文件名的两个字符名,trail文件名共8个字符,其余6个字符由GoldenGate系列填充;
GGSCI (sywu as ogg_owner@sydb) 14> ADD EXTTRAIL /u01/app/product/ogg_src/dirdat/es, EXTRACT esydb001
EXTTRAIL added.
2.2.1.1 配置主抽取进程(Primary Extract)参数
GGSCI (sywu as ogg_owner@sydb) 15> edit param esydb001
extract esydb001
SETENV(ORACLE_SID="sydb")
SETENV(NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg_owner, password ogg_owner
EXTTRAIL /u01/app/product/ogg_src/dirdat/es
table ogg_owner.togg;
userid指定GoldenGate 抽取用户的用户名和密码;
SETENV 设置环境变量,如实例名、数据库字符集;
table 指定抽取的用户和表名,如果指定多个以相同字符开头或结尾的表名,可以使用“前缀* ”的方式代替,这里仅以ogg_owner.togg表为测试案例;
2.2.2 创建和配置Data Pump进程(Secondly Extract)
添加Data Pump Extract进程时要注意,如果源端和目标端OGG物理路径都相同,可以按照常规方式处理,但是如果不相同,就像我本例的一样源端和目标端都在同一台机器上,但GoldenGate物理路径不相同,请按如下方式处理
2.2.2.1 创建Data Pump Extract进程
GGSCI (sywu) 26> ADD EXTRACT PSYDB001, EXTTRAILSOURCE /u01/app/product/ogg_src/dirdat/es
EXTRACT added.
EXTTRAILSOUCE 指定源端的trail路径,必须包含两个字符,这个路径和主抽取进程(Primary Extract)中指定的trail目录和trail文件命名必须相同,因为Data Pump进程要读取主抽取进程生成的trail文件;
2.2.2.2 配置Data Pump Extract进程
edit param psydb001
extract psydb001
SETENV(ORACLE_SID="sydb")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg_owner,password ogg_owner
RMTHOST sywu,mgrport 7909
RMTTRAIL /u01/app/product/ogg_trg/dirdat/ps --这里指定目标端trail文件位置,同样包含两个字符
table ogg_owner.togg;
RMTHOST 指定目标端地址和端口等信息;
RMTTRAIL 指定目标端保存trail文件的目录和两个字符文件名;
TABLE 指定同步的表,配置的方式同在主抽取进程(Primary Extract)的配置一样,但这里多了许多额外的功能,比如实现数据过滤和其它复杂操作;
2.2.2.3 将目标端trail文件添加到队列中
源端可以配置多个主抽取进程,也可以配置多个Data Pump进程,但必须为每个要同步的目标端配置一个Data Pump进程;
GGSCI (sywu) 10> ADD RMTTRAIL /u01/app/product/ogg_trg/dirdat/ps, EXTRACT PSYDB001
RMTTRAIL added.
2.3 在目标端配置Replicat
目标端需要做的工作:
创建和配置Checkpoint Table
创建和配置Replicat进程
2.3.1 创建和配置Checkpoint Table
目标端Replicat进程监控Checkpoint
Table,每一条接收到的checkpoint数据由Collector后台进程写入到Checkpoint
Table,因为对于事务来说每一条checkpoint数据要么执行成功要么执行失败,所以Replicat进程确保每一条checkpoint事务数
据只应用一次,即使其它进程错误或者数据库错误。
在目标端GSSCI命令行下使用dblogin登录到目标端OGG管理用户
[oracle@sywu ogg_src]$ tggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu) 1> dblogin userid ogg_trg,password ogg_trg
Successfully logged into database.
创建checkpoint table
GGSCI (sywu as ogg_trg@sydb) 2> add checkpointtable ogg_trg.ogg_chk
Successfully created checkpoint table ogg_trg.ogg_chk.
将checkpoint table 定义在GoldenGate配置文件里
GGSCI (sywu) 1> edit param ./GLOBALS
GGSCHEMA OGG_TRG
CHECKPOINTTABLE OGG_TRG.OGG_CHK
首次编辑GoldenGate配置文件时,GLOBALS文件以大写命名并且没有扩展名创建在GoldenGate_home根目录。
2.3.2 创建和配置Replicat进程
当GoldenGate运行时会产生一些与同步数据不相关的文件,这些文件记录了GoldenGate进程错误、数据库错误、
GoldenGate操作等信息,这个文件叫做Discard
file,配置Replicat进程时由DISCARDFILE参数定义,这个参数是可选的,但推荐创建相应的目录并配置,方便诊断GoldenGate
错误问题;
创建Discard file目录
[oracle@sywu ogg_trg]$ mkdir /u01/app/product/ogg_trg/discrd
[oracle@sywu ogg_trg]$ chmod 775 /u01/app/product/ogg_trg/discrd/
目标端创建Replicat进程
GGSCI (sywu) 27> add replicat rsydb001,exttrail /u01/app/product/ogg_trg/dirdat/ps,checkpointtable OGG_TRG.OGG_CHK
REPLICAT added.
编辑Replicat进程配置文件
REPLICAT rsydb001
SETENV(ORACLE_SID="sydb")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID ogg_trg,password ogg_trg
DISCARDFILE /u01/app/product/ogg_trg/discrd/reptr.desc,append,megabytes 512
ALLOWNOOPUPDATES
ASSUMETARGETDEFS
MAP OGG_OWNER.TOGG,target OGG_TRG.TOGG;
到这里简单的源端和目标端的MGR、Extract、Replicat进程就配置完了,测试配置文件是否错误,进程启动是否正常,如果进程有问题就使用“view report 进程名”查看错误;不要将所有进程启动,因为有些工作还没有完成。
3 初始化数据
为什么要初始化数据?
因为DML操作包括INSERT、UPDATE、DELETE、SELECT操作,而在这些操作中UPDATE、
DELETE操作Redo只记录了变更的数据列以及行ID(ROWID),GoldenGate抽取数据后将其转换为自己的格式发送都目标端,假设源端有
100条数据,从08:00 AM开始同步到目标端,而在同步开始前目标端没有初始化数据(目标端为空数据),那么08:00
AM后事物产生的UPDATE、DELETE DML操作发送到目标端,目标端GoldenGate
Replicat进程会因为找不到数据而报错从而导致Replicat进程崩溃停止(ABENDED),所以这就需要我们在同步前初始化数据,初始化完后
再同步,这样大大降低错误率。同步数据的方式可以通过DBLINK、EXP/IMP、SQLLDR或者表空间迁移等方式同步;我的测试都在同一个库所以就
直接创建表了。
SYS@sydb>create table ogg_trg.togg as select * from ogg_owner.togg
2 /
Table created.
Elapsed: 00:00:00.24
4 使用GoldenGate
数据初始化后,分别启动源端MGR进程、主抽取进程(Primary Extract)、Data Pump进程(Secondly Extract)以及目标端MGR进程、Replicat进程;
启动源端GoldenGate进程
[oracle@sywu ~]$ sggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu) 1> start mgr
Manager started.
GGSCI (sywu) 2> start PSYDB001
Sending START request to MANAGER ...
EXTRACT PSYDB001 starting
GGSCI (sywu) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING ESYDB001 00:00:00 00:00:02
EXTRACT RUNNING PSYDB001 00:00:00 12:41:34
启动目标端GoldenGate进程
[oracle@sywu ~]$ tggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu) 1> start mgr
Manager started.
GGSCI (sywu) 2> start RSYDB001
Sending START request to MANAGER ...
REPLICAT RSYDB001 starting
GGSCI (sywu) 3> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING RSYDB001 00:00:00 00:00:07
进程都启动完了,此时观察源端和目标端trail文件生成情况
[oracle@sywu ~]$ ls -ltr /u01/app/product/ogg_src/dirdat
total 324
-rw-r-----. 1 oracle oinstall 1418 Aug 26 09:42 es000000
-rw-r-----. 1 oracle oinstall 1481 Aug 26 09:48 es000001
-rw-r-----. 1 oracle oinstall 1481 Aug 26 09:50 es000002
-rw-r-----. 1 oracle oinstall 1481 Aug 26 09:52 es000003
-rw-r-----. 1 oracle oinstall 1481 Aug 26 09:52 es000004
[oracle@sywu ~]$ ls -ltr /u01/app/product/ogg_trg/dirdat
total 324
-rw-r-----. 1 oracle oinstall 193469 Aug 25 13:00 ps000000
-rw-r-----. 1 oracle oinstall 891 Aug 25 13:00 ps000001
-rw-r-----. 1 oracle oinstall 1652 Aug 25 13:07 ps000002
-rw-r-----. 1 oracle oinstall 891 Aug 25 13:07 ps000003
-rw-r-----. 1 oracle oinstall 105884 Aug 25 13:49 ps000004
-rw-r-----. 1 oracle oinstall 891 Aug 25 13:49 ps000005
-rw-r-----. 1 oracle oinstall 2095 Aug 26 09:54 ps000006
-rw-r-----. 1 oracle oinstall 1201 Aug 26 09:54 ps000007
-rw-r-----. 1 oracle oinstall 2032 Aug 26 09:54 ps000008
源端进程信息
GGSCI (sywu) 4> info ESYDB001,detail
EXTRACT ESYDB001 Last Started 2015-08-26 09:52 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:10 ago)
Process ID 14619
Log Read Checkpoint Oracle Redo Logs
2015-08-26 09:58:11 Seqno 13, RBA 1942016
SCN 0.575310 (575310)
Target Extract Trails:
Trail Name Seqno RBA Max MB Trail Type
/u01/app/product/ogg_src/dirdat/es 4 1481 100 EXTTRAIL
Extract Source Begin End
/u01/oradata/sydb/redo01.log 2015-08-26 09:52 2015-08-26 09:58
/u01/oradata/sydb/redo01.log 2015-08-26 09:49 2015-08-26 09:52
/u01/oradata/sydb/redo01.log 2015-08-26 09:43 2015-08-26 09:49
/u01/oradata/sydb/redo01.log 2015-08-26 09:40 2015-08-26 09:43
/u01/oradata/sydb/redo01.log 2015-08-25 20:43 2015-08-26 09:40
Not Available * Initialized * 2015-08-25 20:43
Not Available * Initialized * 2015-08-25 20:43
Current directory /u01/app/product/ogg_src
Report file /u01/app/product/ogg_src/dirrpt/ESYDB001.rpt
Parameter file /u01/app/product/ogg_src/dirprm/esydb001.prm
Checkpoint file /u01/app/product/ogg_src/dirchk/ESYDB001.cpe
Process file /u01/app/product/ogg_src/dirpcs/ESYDB001.pce
Error log /u01/app/product/ogg_src/ggserr.log
GGSCI (sywu) 5> info PSYDB001,detail
EXTRACT PSYDB001 Last Started 2015-08-26 09:52 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:04 ago)
Process ID 14648
Log Read Checkpoint File /u01/app/product/ogg_src/dirdat/es000004
2015-08-26 09:52:50.035063 RBA 1481
Target Extract Trails:
Trail Name Seqno RBA Max MB Trail Type
/u01/app/product/ogg_trg/dirdat/ps 0 0 100 EXTTRAIL
Extract Source Begin End
/u01/app/product/ogg_src/dirdat/es000004 * Initialized * 2015-08-26 09:52
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
Current directory /u01/app/product/ogg_src
Report file /u01/app/product/ogg_src/dirrpt/PSYDB001.rpt
Parameter file /u01/app/product/ogg_src/dirprm/psydb001.prm
Checkpoint file /u01/app/product/ogg_src/dirchk/PSYDB001.cpe
Process file /u01/app/product/ogg_src/dirpcs/PSYDB001.pce
Error log /u01/app/product/ogg_src/ggserr.log
GGSCI (sywu) 6> stats ESYDB001
Sending STATS request to EXTRACT ESYDB001 ...
No active extraction maps.
GGSCI (sywu) 7> stats PSYDB001
Sending STATS request to EXTRACT PSYDB001 ...
No active extraction maps.
目标端进程信息
GGSCI (sywu) 5> info RSYDB001,detail
REPLICAT RSYDB001 Last Started 2015-08-26 09:55 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:08 ago)
Process ID 15105
Log Read Checkpoint File /u01/app/product/ogg_trg/dirdat/ps000008
First Record RBA 2032
Current Log BSN value: (requires database login)
Last Committed Transaction CSN value: (requires database login)
Extract Source Begin End
/u01/app/product/ogg_trg/dirdat/ps000008 2015-08-26 09:52 First Record
/u01/app/product/ogg_trg/dirdat/ps000008 2015-08-25 13:58 2015-08-26 09:52
/u01/app/product/ogg_trg/dirdat/ps000006 2015-08-25 13:49 2015-08-25 13:58
/u01/app/product/ogg_trg/dirdat/ps000006 2015-08-25 13:49 2015-08-25 13:49
/u01/app/product/ogg_trg/dirdat/ps000006 2015-08-25 13:49 2015-08-25 13:49
/u01/app/product/ogg_trg/dirdat/ps000006 * Initialized * 2015-08-25 13:49
/u01/app/product/ogg_trg/dirdat/ps000006 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
Current directory /u01/app/product/ogg_trg
Report file /u01/app/product/ogg_trg/dirrpt/RSYDB001.rpt
Parameter file /u01/app/product/ogg_trg/dirprm/rsydb001.prm
Checkpoint file /u01/app/product/ogg_trg/dirchk/RSYDB001.cpr
Checkpoint table OGG_TRG.OGG_CHK
Process file /u01/app/product/ogg_trg/dirpcs/RSYDB001.pcr
Error log /u01/app/product/ogg_trg/ggserr.log
GGSCI (sywu) 6> stats RSYDB001
Sending STATS request to REPLICAT RSYDB001 ...
No active replication maps.
在源端产生DML操作
OGG_OWNER@sydb>insert into togg(id,name)values(1003,'tt') ;
1 row created.
Elapsed: 00:00:00.00
OGG_OWNER@sydb>insert into togg(id,name,type)values(1004,'sywu','user');
1 row created.
Elapsed: 00:00:00.01
OGG_OWNER@sydb>commit;
Commit complete.
Elapsed: 00:00:00.01
再次查看源端进程状态
GGSCI (sywu) 10> stats ESYDB001
Sending STATS request to EXTRACT ESYDB001 ...
Start of Statistics at 2015-08-26 10:04:54.
Output to /u01/app/product/ogg_src/dirdat/es:
Extracting from OGG_OWNER.TOGG to OGG_OWNER.TOGG:
*** Total statistics since 2015-08-26 10:04:33 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Daily statistics since 2015-08-26 10:04:33 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Hourly statistics since 2015-08-26 10:04:33 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Latest statistics since 2015-08-26 10:04:33 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
End of Statistics.
GGSCI (sywu) 11> stats PSYDB001
Sending STATS request to EXTRACT PSYDB001 ...
Start of Statistics at 2015-08-26 10:04:58.
Output to /u01/app/product/ogg_trg/dirdat/ps:
Extracting from OGG_OWNER.TOGG to OGG_OWNER.TOGG:
*** Total statistics since 2015-08-26 10:04:35 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Daily statistics since 2015-08-26 10:04:35 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Hourly statistics since 2015-08-26 10:04:35 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Latest statistics since 2015-08-26 10:04:35 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
End of Statistics.
再次查看目标端进程状态
GGSCI (sywu) 7> stats RSYDB001
Sending STATS request to REPLICAT RSYDB001 ...
Start of Statistics at 2015-08-26 10:05:03.
Replicating from OGG_OWNER.TOGG to OGG_TRG.TOGG:
*** Total statistics since 2015-08-26 10:04:45 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Daily statistics since 2015-08-26 10:04:45 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Hourly statistics since 2015-08-26 10:04:45 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Latest statistics since 2015-08-26 10:04:45 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
End of Statistics.
数据稽查
SYS@sydb>select count(*) from ogg_owner.togg;
COUNT(*)
----------
1002
Elapsed: 00:00:00.00
SYS@sydb>select count(*) from ogg_trg.togg;
COUNT(*)
----------
1002
Elapsed: 00:00:00.05
SYS@sydb>column name format a10
SYS@sydb>select id,name,type from ogg_owner.togg where name='sywu';
ID NAME TYPE
---------- ---------- -------------------
1004 sywu user
Elapsed: 00:00:00.00
SYS@sydb>select id,name,type from ogg_trg.togg where name='sywu';
ID NAME TYPE
---------- ---------- -------------------
1004 sywu user
Elapsed: 00:00:00.01
5 总结
GoldenGate通过自身的数据加工、处理、发送、应用以及借用RDBMS数据库系统的优势保证数据的可同步性和准确性,并在错误和故障发
生的情况下以RDBMS系统特有的特性(如Oracle
内部同步变更号(SCN)和检查点)保障了数据的可恢复性和一致性,为同步的数据实时性和准确性提供了准确性和可稽查性。
三、加密
阅读导航
写在开始前
1 加密的使用场景
2 GoldenGate提供的加密算法
3 产生密钥
4 源端加密配置
4.1 配置主抽取进程
4.2 配置Data Pump进程
5 目标端解密配置
5.1 Replicat进程配置解密操作
6 未加密和加密trail文件对比分析
6.1 未加密trail文件分析
6.2 加密trail文件分析
7 OBEY文件
8 总结
写在开始前
从上周开始,我花了大量的业余时间阅读GoldenGate官方文档,并根据文档实践和进一步学习了解GoldenGate,以下便是根据官方文档理解总结的GoldenGate学习内容:
GoldenGate 学习教程一:介绍和安装
Oracle GoldenGate 学习教程二、配置和使用
在[美] 莫提默·J.艾德勒,[美] 查尔斯·范多伦著的【How to Read a
Book】一书中,作者强调如果你每天所学的知识你不能用你自己的语言去描述或记忆它,那说明你未真正学习和了解所学的知识,So
那以后我改变了我的学习方式,把生搬硬套的学习方式改变为用自己的语言用、自己的了解去描述和记忆知识,描述难免有错,请谅解,也请指导,谢谢!
1 加密的使用场景
GoldenGate参数文件
在每个Extract进程和Replicat进程的USERID、TRANLOGOPTIONS、
DDLOPTIONS、DBOPTIONS参数中都要指定密码,密码是比较敏感又比较重要的信息,因为GoldenGate用户具有比较多的数据库权限,
所以有效的保护密码是GoldenGate关于安全的首要之一。
trail文件
主抽取进程(Primary Extract)从数据库中抽取变更信息并加密写入到trail文件,然后再由Data
Pump(Secondly
Extract)进程解密实现复杂操作,加密成最终trail文件通过网络发送到目标端,目标端GoldenGate后台collector进程将
trail文件保存到目标端trail文件,replicat进程读取文件内容并将其解密、重构、应用到目标库。
GGSCI命令行
使用DBLOGIN登录数据库时提供的密码。
2 GoldenGate提供的加密算法
AES128
使用AES 128加密,具有128位的密钥大小
AES192
使用AES 192加密,具有192位的密钥大小
AES256
使用AES 256加密,具有256位的密钥大小
BLOWFISH
使用64位块大小和从32位到128位的可变长度密钥的Blowfish加密,建议只在GoldenGate较早版本中使用,仅在ENCRYPTKEY为DEFAULT时可使用此种加密方式。
3 产生密钥
必须先产生密钥并且保存在ENCKEYS LookUp文件中然后才能使用以下功能
使用ENCRYPT PASSWORD PWD ENCRYPTKEY 生成加密密码
在配置文件参数ENCRYPTTRAIL KEYNAME 中指定trail文件加密方式和密钥名
在配置文件参数RMHOST或RMTHOSTOPTIONS ENCRYPT 中指定加密方式和密钥名
产生密钥
切换到GoldenGate home 目录,使用KEYGEN工具产生密钥;语法:
./keygen
key length 表示加密密钥的长度;
n 表示产生多少个key;
[oracle@sywu ogg_src]$ ./keygen 128 2
0xDEE44B0133536B0DA1B858620E4A240D
0x71DF8D01C352097FC76BBA31232DA95A
每一次产生的key都是不一样的,产生key后为每一个key定义一个名称(keyName)复制保存到GoldenGate home根目录的ENCKEYS文件内。ENCKEYS文件是一个lookup file。
保存key到ENCKEYS文件
[oracle@sywu ogg_src]$ vim ENCKEYS
#GoldenGate encryption key
#keyName key
securekey1 0xDEE44B0133536B0DA1B858620E4A240D
securekey2 0x71DF8D01C352097FC76BBA31232DA95A
在GGSCI命令行通过key对密码加密
GGSCI (sywu) 8> encrypt password ogg_owner aes128 encryptkey securekey1
Encrypted password: AADAAAAAAAAAAAJATJEEYELAGIQFZDWHQAMDMCCHGIVGFIPHOCABMAYCHGSCPHGILCPCLCXCCHUEFGOC
Algorithm used: AES128
GGSCI (sywu) 9> encrypt password ogg_owner aes128 encryptkey securekey1
Encrypted password: AADAAAAAAAAAAAJANJBHVDBAGCCBOIUCTJHJVIOCVGBFSGNJFFAAGIOHBJNBWAPANGWILCPFGIXBOIXB
Algorithm used: AES128
密码加密后可以尝试使用dblogin登录数据库,验证密码
GGSCI (sywu as ogg_owner@sydb) 11> dblogin userid ogg_owner,password AADAAAAAAAAAAAJANJBHVDBAGCCBOIUCTJHJVIOCVGBFSGNJFFAAGIOHBJNBWAPANGWILCPFGIXBOIXB aes128 encryptkey securekey1
Successfully logged into database.
注意:因为在创建key时指定了key的长度,所以使用时指定的加密类型密钥长度也必须一致。
4 源端加密配置
源端配置主抽取进程加密和Data Pump进程加密。
4.1 配置主抽取进程
GGSCI (sywu as ogg_owner@sydb) 31> EDIT PaRAM ESYDB001
extract ESYDB001
SETENV(ORACLE_SID="sydb")
SETENV(NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg_owner,password AADAAAAAAAAAAAJANJBHVDBAGCCBOIUCTJHJVIOCVGBFSGNJFFAAGIOHBJNBWAPANGWILCPFGIXBOIXB &
aes128,ENCRYPTKEY securekey1
ENCRYPTTRAIL aes128,KEYNAME securekey1
EXTTRAIL /u01/app/product/ogg_src/dirdat/es
table ogg_owner.togg;
userid 中将password由原来的明码用加密后的密码代替,后面指定加密类型和密钥名称(ENCRYPTKEY);
ENCRYPTTRAIL 指定trail文件的加密类型和密钥名称(KEYNAME);
4.2 配置Data Pump进程
GGSCI (sywu) 10> edit param PSYDB001
extract psydb001
SETENV(ORACLE_SID="sydb")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg_owner,password AADAAAAAAAAAAAJANJBHVDBAGCCBOIUCTJHJVIOCVGBFSGNJFFAAGIOHBJNBWAPANGWILCPFGIXBOIXB aes128 encryptkey securekey1
DECRYPTTRAIL aes128 KEYNAME securekey1
RMTHOST sywu,mgrport 7909
ENCRYPTTRAIL aes128 KEYNAME securekey1
RMTTRAIL /u01/app/product/ogg_trg/dirdat/ps
TABLE ogg_owner.togg;
因为Data Pump要读取主抽取进程保存的trail文件数据并且提供了对数据的操作功能如实现过滤、运算等复杂的工作,所以在读取后必须先对原数据进行解密再处理,最后再次加密发送到目标端;
DECRYPTTRAIL 定义将要解密的文件的加密类型和加密key(KEYNAME);
ENCRYPTTRAIL 定义最终处理后的数据加密类型和加密key(KEYNAME);
注意:解密类型和keyname必须和主进程配置的相同。
启动进程
GGSCI (sywu as ogg_owner@sydb) 42> start *
Sending START request to MANAGER ...
EXTRACT ESYDB001 starting
EXTRACT PSYDB001 is already running.
GGSCI (sywu as ogg_owner@sydb) 43> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING ESYDB001 00:01:31 00:00:08
EXTRACT RUNNING PSYDB001 00:00:00 116:02:26
5 目标端解密配置
目标端后台Collector进程在接受到源端的发送请求后将数据写入到目标端trail文件中,再由replicat进程读取、解密、重构dml
或ddl语句应用到数据库,so 如果源端配置了加密则目标端必须进行解密配置,并且解密的类型和key必须和源端相同,操作步骤:
1 将源端创建的ENCKEYS文件发送到目标端GoldenGate根目录
2 Replicat进程配置解密操作
3 重启replicat进程
发送源端ENCKEYS文件到目标端可以scp或复制粘贴到目标端,此处省略其操作。
5.1 Replicat进程配置解密操作
[oracle@sywu ~]$ tggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu) 1> edit param RSYDB001
REPLICAT rsydb001
SETENV(ORACLE_SID="sydb")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
USERID ogg_trg,password AADAAAAAAAAAAAHABDQFVJMADCAFECACYEPIQEJCFGDGMDHBRJXCUBOBQJEGLBPEBDMCOAACDILGAJKA &
aes128,ENCRYPTKEY securekey1
DISCARDFILE /u01/app/product/ogg_trg/discrd/reptr.desc,append,megabytes 512
DECRYPTTRAIL AES128, KEYNAME securekey1
ALLOWNOOPUPDATES
ASSUMETARGETDEFS
MAP OGG_OWNER.TOGG,target OGG_TRG.TOGG;
DECRYPTTRAIL 定义将要解密的文件的加密类型和加密密钥(KEYNAME),这里和源端必须相同;
这些都配置好了,重启replicat 进程。
6 未加密和加密trail文件对比分析
6.1 未加密trail文件分析
[oracle@sywu ~]$ strings /u01/app/product/ogg_src/dirdat/es000004
*uri:sywu::u01:app:product:ogg_src:ESYDB0016
(/u01/app/product/ogg_src/dirdat/es0000047
575523
575169
,............................................
Linux1
sywu2
2.6.32-431.23.3.el6.x86_643
##1 SMP Thu Jul 31 17:20:51 UTC 20144
x86_642
SYDB2
sydb3
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
11.2.0.3.09
+08:003
ESYDB0011
AVersion 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO4
ESYDB001Z
OGG_OWNER.TOGG
1003
1900-01-01:00:00:00
1900-01-01:00:00:00T
AAADX2AAGAAAAA2AAA
5755236
2.138.127Z
OGG_OWNER.TOGG
1004
sywu
user
1900-01-01:00:00:00
1900-01-01:00:00:00T
AAADX2AAGAAAAA2AAB
以上的trail文件来自上次未加密的测试环境中,具体的dml
OGG_OWNER@sydb>insert into togg(id,name)values(1003,'tt') ;
1 row created.
Elapsed: 00:00:00.00
OGG_OWNER@sydb>insert into togg(id,name,type)values(1004,'sywu','user');
1 row created.
Elapsed: 00:00:00.01
So 在未加密情况下可以清楚的看到新增的id(1003,1004)和rowid(AAADX2AAGAAAAA2AAA,AAADX2AAGAAAAA2AAB);
6.2 加密trail文件分析
在源端插入如下数据:
SYS@sydb>conn ogg_owner/ogg_owner
Connected.
OGG_OWNER@sydb>insert into togg(id,name,type)values(1005,'sywu','user');
1 row created.
Elapsed: 00:00:00.09
OGG_OWNER@sydb>insert into togg(id,name,type)values(1006,'sywu','user');
1 row created.
Elapsed: 00:00:00.01
OGG_OWNER@sydb>commit;
Commit complete.
Elapsed: 00:00:00.00
分析GoldenGate Data Pump进程
GGSCI (sywu) 11> stats PSYDB001
Sending STATS request to EXTRACT PSYDB001 ...
Start of Statistics at 2015-08-31 17:32:14.
Output to /u01/app/product/ogg_trg/dirdat/ps:
Extracting from OGG_OWNER.TOGG to OGG_OWNER.TOGG:
*** Total statistics since 2015-08-31 17:29:53 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Daily statistics since 2015-08-31 17:29:53 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Hourly statistics since 2015-08-31 17:29:53 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Latest statistics since 2015-08-31 17:29:53 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
End of Statistics.
GGSCI (sywu) 12> info PSYDB001,detail
EXTRACT PSYDB001 Last Started 2015-08-31 17:17 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:01 ago)
Process ID 31884
Log Read Checkpoint File /u01/app/product/ogg_src/dirdat/es000007
2015-08-31 17:29:49.000000 RBA 1865
Target Extract Trails:
Trail Name Seqno RBA Max MB Trail Type
/u01/app/product/ogg_trg/dirdat/ps 10 2043 100 RMTTRAIL
Extract Source Begin End
/u01/app/product/ogg_src/dirdat/es000007 2015-08-26 10:04 2015-08-31 17:29
/u01/app/product/ogg_src/dirdat/es000004 2015-08-26 10:04 2015-08-26 10:04
/u01/app/product/ogg_src/dirdat/es000004 2015-08-26 10:04 2015-08-26 10:04
/u01/app/product/ogg_src/dirdat/es000004 2015-08-26 10:04 2015-08-26 10:04
/u01/app/product/ogg_src/dirdat/es000004 2015-08-26 10:04 2015-08-26 10:04
/u01/app/product/ogg_src/dirdat/es000004 2015-08-26 10:04 2015-08-26 10:04
/u01/app/product/ogg_src/dirdat/es000004 * Initialized * 2015-08-26 10:04
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
/u01/app/product/ogg_src/dirdat/es000000 * Initialized * First Record
Current directory /u01/app/product/ogg_src
Report file /u01/app/product/ogg_src/dirrpt/PSYDB001.rpt
Parameter file /u01/app/product/ogg_src/dirprm/psydb001.prm
Checkpoint file /u01/app/product/ogg_src/dirchk/PSYDB001.cpe
Process file /u01/app/product/ogg_src/dirpcs/PSYDB001.pce
Error log /u01/app/product/ogg_src/ggserr.log
源端Data
Pump进程从主抽取进程保存的trail文件中读取到两条插入信息,它读取的trail文件是:/u01/app/product/ogg_src
/dirdat/es000007;注意它们的工作原理,主抽取进程抽取数据加密并保存到trail文件,Data
Pump进程读取trail文件解密再进行数据操作,最后发送;
[oracle@sywu ~]$ strings /u01/app/product/ogg_src/dirdat/es000007
*uri:sywu::u01:app:product:ogg_src:ESYDB0016
(/u01/app/product/ogg_src/dirdat/es0000077
597066
,............................................
Linux1
sywu2
2.6.32-431.23.3.el6.x86_643
##1 SMP Thu Jul 31 17:20:51 UTC 20144
x86_642
SYDB2
sydb3
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
11.2.0.3.09
+08:003
ESYDB0011
AVersion 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO4
ESYDB001Z
OGG_OWNER.TOGG
AAADX2AAGAAAAA7AAA
5981816
1.86.100Z
OGG_OWNER.TOGG
uaDL
AAADX2AAGAAAAA7AAB
数据加密了,看不到了。
源端replicat进程信息
[oracle@sywu ogg_src]$ tggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Aug 7 2014 09:14:25
Operating system character set identified as UTF-8.
Copyright (C) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
GGSCI (sywu) 1> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING RSYDB001 00:00:00 00:00:03
GGSCI (sywu) 4> stats RSYDB001
Sending STATS request to REPLICAT RSYDB001 ...
Start of Statistics at 2015-08-31 18:40:08.
Replicating from OGG_OWNER.TOGG to OGG_TRG.TOGG:
*** Total statistics since 2015-08-31 17:30:03 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Daily statistics since 2015-08-31 17:30:03 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
*** Hourly statistics since 2015-08-31 18:00:00 ***
No database operations have been performed.
*** Latest statistics since 2015-08-31 17:30:03 ***
Total inserts 2.00
Total updates 0.00
Total deletes 0.00
Total discards 0.00
Total operations 2.00
End of Statistics.
GGSCI (sywu) 2> info RSYDB001,detail
REPLICAT RSYDB001 Last Started 2015-08-31 17:16 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:05 ago)
Process ID 31615
Log Read Checkpoint File /u01/app/product/ogg_trg/dirdat/ps000010
2015-08-31 17:29:49.000465 RBA 2043
Current Log BSN value: (requires database login)
Last Committed Transaction CSN value: (requires database login)
Extract Source Begin End
/u01/app/product/ogg_trg/dirdat/ps000010 2015-08-26 10:04 2015-08-31 17:29
/u01/app/product/ogg_trg/dirdat/ps000008 2015-08-26 09:52 2015-08-26 10:04
/u01/app/product/ogg_trg/dirdat/ps000008 2015-08-25 13:58 2015-08-26 09:52
/u01/app/product/ogg_trg/dirdat/ps000006 2015-08-25 13:49 2015-08-25 13:58
/u01/app/product/ogg_trg/dirdat/ps000006 2015-08-25 13:49 2015-08-25 13:49
/u01/app/product/ogg_trg/dirdat/ps000006 2015-08-25 13:49 2015-08-25 13:49
/u01/app/product/ogg_trg/dirdat/ps000006 * Initialized * 2015-08-25 13:49
/u01/app/product/ogg_trg/dirdat/ps000006 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
/u01/app/product/ogg_trg/dirdat/ps000000 * Initialized * First Record
Current directory /u01/app/product/ogg_trg
Report file /u01/app/product/ogg_trg/dirrpt/RSYDB001.rpt
Parameter file /u01/app/product/ogg_trg/dirprm/rsydb001.prm
Checkpoint file /u01/app/product/ogg_trg/dirchk/RSYDB001.cpr
Checkpoint table OGG_TRG.OGG_CHK
Process file /u01/app/product/ogg_trg/dirpcs/RSYDB001.pcr
Error log /u01/app/product/ogg_trg/ggserr.log
目标端同样插入两条数据,replicate进程从/u01/app/product/ogg_trg/dirdat/ps000010文件中读取了后台collector进程接受到的trail数据。
[oracle@sywu ~]$ strings /u01/app/product/ogg_trg/dirdat/ps000010
*uri:sywu::u01:app:product:ogg_src:PSYDB0015
*uri:sywu::u01:app:product:ogg_src:ESYDB0016
(/u01/app/product/ogg_trg/dirdat/ps0000107
598181
594135
,............................................
Linux1
sywu2
2.6.32-431.23.3.el6.x86_643
##1 SMP Thu Jul 31 17:20:51 UTC 20144
x86_642
SYDB2
sydb3
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
11.2.0.3.09
+08:003
ESYDB0011
AVersion 12.1.2.1.0 OGGCORE_12.1.2.1.0_PLATFORMS_140727.2135.1_FBO4
ESYDB001Z
ESYDB001Z
ESYDB001Z
OGG_OWNER.TOGG
AAADX2AAGAAAAA7AAA
5981816
1.86.100Z
OGG_OWNER.TOGG
uaDL
AAADX2AAGAAAAA7AAB
文件的信息同样是加密的,replicate读取后进行解密、重构、应用到目标库。
7 OBEY文件
GodlenGate的每个Extract、Replicat进程都需要配置数据库连接,随着进程的增加和各自分工不同或数据交换的目标地不
同,如果每个都这样配置,那当数据库用户密码改变了,那岂不是要大动干戈的修改,有没有什么方式可以像面向对象设计一样把公共的部分提取出来呢?肯定有
了,GoldenGate提供了一个叫OBEY的参数,允许将公共常用的部分提取保存到独立的文件中实现共享和重用,例如下面的进程配置:
GGSCI (sywu) 2> view param PSYDB001
extract psydb001
SETENV(ORACLE_SID="sydb")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
userid ogg_owner,password AADAAAAAAAAAAAJANJBHVDBAGCCBOIUCTJHJVIOCVGBFSGNJFFAAGIOHBJNBWAPANGWILCPFGIXBOIXB aes128 encrypt
key securekey1
DECRYPTTRAIL aes128 KEYNAME securekey1
RMTHOST sywu,mgrport 7909
ENCRYPTTRAIL aes128 KEYNAME securekey1
RMTTRAIL /u01/app/product/ogg_trg/dirdat/ps
TABLE ogg_owner.togg;
数据库连接、DECRYPTTRAIL、RMTHOST这些参数基本都是共用和不常变的,so 可以将其保存到独立的文件中;
[oracle@sywu dirdef]$ vim /u01/app/product/ogg_src/dirdef/dbConnect.obey
userid ogg_owner,password AADAAAAAAAAAAAJANJBHVDBAGCCBOIUCTJHJVIOCVGBFSGNJFFAAGIOHBJNBWAPANGWILCPFGIXBOIXB aes128 encrypt
key securekey1
DECRYPTTRAIL aes128 KEYNAME securekey1
RMTHOST sywu,mgrport 7909
然后在进程参数配置文件中通过OBEY引用该文件;
extract psydb001
SETENV(ORACLE_SID="sydb")
SETENV (NLS_LANG=AMERICAN_AMERICA.AL32UTF8)
OBEY /u01/app/product/ogg_src/dirdef/dbConnect.obey
ENCRYPTTRAIL aes128 KEYNAME securekey1
RMTTRAIL /u01/app/product/ogg_trg/dirdat/ps
TABLE ogg_owner.togg;
这样以后涉及数据库连接的信息就只用更改该文件了,GoldenGate支持16级子文件递归调用,这也就意外着可以将更多的配置细化管理。
8 总结
GoldenGate提供了AES128、AES192、AES256和BLOWFISH类型加密,BLOWFISH在keyname为
default时可用,一般用于较早版本中,AES类型的加密更为安全。主抽取进程的加密是可选的,可以只在Data
Pump进程中进行数据加密。进程的加密要考虑到加密的长度和密钥名称,必须先用GoldenGate提供的工具keygen或其它的工具生成密钥保存在
ENCKEYS
lookUp文件中,然后在GGSCI命令行中根据密码类型和ENCKEYS中的密钥名称生成加密密码,最后在配置文件或GGSCI命令中使用加密密码。
目标端必须具有和源端相同的ENCKEYS lookUp文件并且在配置解密时,加密解密的类型和密钥名称要一致。