http://www.dataguru.cn/thread-171156-1-1.html
GoldenGate几个重要进程介绍:
1、Manager管理进程在两端开启,监控和重启其他进程;分配数据存储和报告错误及事件;
2、Extract进程从日志中抓取并传输到target端事务数据;
3、Server Collector进程在target(接受)端接受数据并写入trail文件;
4、Replicat进程读取trail文件,并应用到traget数据库;
5、trail文件时gg自己抓捕信息的文件,是一个OS文件,存放在./dirdat/下,以X00000命名,N顺序1,2,3…此文件用完可配置参数自动删除。
问题:
1、数据库设置为归档模式
2、特别注意抽取进程、投递进程、接受进程之间的关系
抽取进程定义文件路径为投递进程本地路径add extract pump_so,exttrailsource ./dirdat/et/dd
抽取进程定义远程文件路径为接受进程路径add replicat rep7,exttrail ./dirdat/dp1/sd
一、环境准备并安装GoldenGate
1. 数据库准备情况
1) 源服务器
IP地址:192.168.14.150
数据库:10.2.0.5 64 bit
SID: orcl
操作系统版本:Oracle 5.4 64 bit
数据库:10.2.0.5 64 bit
SID: slave
操作系统版本:Oracle 5.4 64 bit
2. 下载OGG软件并解压安装
1) 源服务器
mkdir -p /u01/app/oracle/ogg
unzip fbo_ggs_Linux_x64_ora10g_64bit.zip
tar -xvf fbo_ggs_Linux_x64_ora10g_64bit.tar -C /u01/app/oracle/ogg/
chown -R oracleinstall /u01/app/oracle/ogg
2) 目标服务器都要配置
mkdir -p /u01/app/oracle/ogg
unzip fbo_ggs_Linux_x64_ora10g_64bit.zip
tar -xvf fbo_ggs_Linux_x64_ora10g_64bit.tar -C /u01/app/oracle/ogg/
chown -R oracle:oinstall /u01/app/oracle/ogg
3. 准备OGG环境变量
#源服务器、与目标服务器都要配置
$ vi /home/oracle/.bash_profile
增加如下一行:
export GGATE=$ORACLE_BASE/ogg
生效环境变量
source /home/oracle/.bash_profile
4. 配置日志模式
# 源服务器,目标服务器不用配置(非双向)
1) 查看规档与日志模式
select log_mode,supplemental_log_data_min,force_logging from v$database;
2) 配置为规档模式
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
alter system set log_archive_dest_1='location=/u01/archive' scope=both;
3) 配置日志模式(打开强制规档与补充日志模式)
alter database add supplemental log data;
alter database force logging;
4)查看配置结果:
SQL> select log_mode,supplemental_log_data_min,force_logging from v$database;
LOG_MODE SUPPLEME FOR
------------ -------- ---
ARCHIVELOG YES YES
5. 创建GoldenGate用户帐号
1) 源服务器
conn / as sysdba;
create tablespace tbs_ogg datafile '/u01/app/oracle/oradata/target/tbs_ogg.dbf' size 10m autoextend on next 10m;
create user ogg identified by ogg default tablespace tbs_ogg temporary tablespace TEMP quota unlimited on tbs_ogg;
grant connect,resource to ogg;
grant create session,alter session to ogg;
grant select any dictionary,select any table to ogg;
grant alter any table to ogg;
grant flashback any table to ogg;
grant execute on dbms_flashback to ogg;
2) 目标服务器
conn / as sysdba;
create tablespace tbs_ogg datafile '/u01/app/oracle/oradata/orcl/tbs_ogg.dbf' size 10m autoextend on next 10m;
create user ogg identified by ogg default tablespace tbs_ogg temporary tablespace TEMP quota unlimited on tbs_ogg;
grant connect,resource to ogg;
grant create session,alter session to ogg;
grant select any dictionary,select any table to ogg;
grant alter any table to ogg;
grant flashback any table to ogg;
grant execute on dbms_flashback to ogg;
grant insert any table to ogg;
grant delete any table to ogg;
grant update any table to ogg;
6. 安装GoldenGate软件
(1) 源服务器、与目标服务器都要配置
./ggsci
GGSCI (test) 1> create subdirs
Parameter files /u01/app/oracle/ogg/dirprm: created
Report files /u01/app/oracle/ogg/dirrpt: created
Checkpoint files /u01/app/oracle/ogg/dirchk: created
Process status files /u01/app/oracle/ogg/dirpcs: created
SQL script files /u01/app/oracle/ogg/dirsql: created
Database definitions files /u01/app/oracle/ogg/dirdef: created
Extract data files /u01/app/oracle/ogg/dirdat: created
Temporary files /u01/app/oracle/ogg/dirtmp: created
Veridata files /u01/app/oracle/ogg/dirver: created
(2) 目标服务器都要配置
./ggsci
GGSCI (slave) 1> create subdirs
Creating subdirectories under current directory /u01/app/oracle/ogg
Parameter files /u01/app/oracle/ogg/dirprm: created
Report files /u01/app/oracle/ogg/dirrpt: created
Checkpoint files /u01/app/oracle/ogg/dirchk: created
Process status files /u01/app/oracle/ogg/dirpcs: created
SQL script files /u01/app/oracle/ogg/dirsql: created
Database definitions files /u01/app/oracle/ogg/dirdef: created
Extract data files /u01/app/oracle/ogg/dirdat: created
Temporary files /u01/app/oracle/ogg/dirtmp: created
Veridata files /u01/app/oracle/ogg/dirver: created
7. 配置源、目标数据库一致
配置源与目标数据一致性可以采用很多方法,可以采用oracle的方式来完成。本方式采用imp方式来实现初始数据表一致。
(1) 源端测试用户:
create user hr identified by hr;
grant connect,resource,select_catalog_role to hr;
conn hr/hr;
create table t1 as select * from dba_objects;
alter table t1 add constraint prikey_t1 primary key(object_id);
(2) 目标端测试用户:
目标服务器通过exp/imp导入过去,只导入表结构
create user hr identified by hr;
grant connect,resource,select_catalog_role to hr;
conn hr/hr;
imp hr/hr file=hr.dmp rows=n
注: 还可以通过goldengate初始化数据加载的方式来实现数据同步
二、 GoldenGate DML同步源端配置
配置思路:
1) 先配置DML同步
2) 再配置DDL同步
./ggsci
1. 源MGR进程并启动
1) 编辑主进程组
PORT 7809
DYNAMICPORTLIST 7800-7900
AUTORESTART EXTRACT *,RETRIES 3, WAITMINUTES 5, RESETMINUTES 60
PURGEOLDEXTRACTS ./dirdat/*/*, USECHECKPOINTS, MINKEEPFILES 100
LAGREPORTMINUTES 1
LAGINFOMINUTES 1
LAGCRITICALMINUTES 1
说明:
port 指定mgr进程通信端口
dynamicportlist 表示mgr进程可以为源与目的端动态通信指定端口
autorestart extract 表示自动重启extract进程组,每2分钟尝试重启所有进程,重试5次,每5分钟清零。
配置参数后,重启mgr进程生效
2) 启动主管理进程
start mgr
2. 配置Extract进程组
1) 编辑配置文件
edit params eora
extract eora
dynamicresolution
SETENV (ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1")
SETENV (ORACLE_SID="source")
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
UsERID ogg password ogg
exttrail ./dirdat/et/dd------------该路径与pump进程密切相关
ddl include all
ddloptions addtrandata, report
table hr.*;
2) 添加抽取进程
add extract eora, tranlog,begin now
3) 添加本地trail文件
ADD EXTTRAIL ./dirdat/et/dd(该路径与pump进程密切相关) EXTRACT eora, MEGABYTES 5
说明:创建本地trail文件,主extract进程负责写这部分文件,pump负责把这部分文件传到目标服务器端。
4) 启动服务
start extract eora
3. 配置Pump进程组
1) 编辑配置文件
edit params pump_so
EXTRACT pump_so
PASSTHRU
DYNAMICRESOLUTION
RMTHOST 192.168.31.14 ,MGRPORT 7809
RMTTRAIL ./dirdat/dp1/sd
DISCARDFILE ./dirrpt/dp2.dsc,APPEND,MEGABYTES 5
DISCARDROLLOVER AT 6:00
REPORTROLLOVER AT 6:00
REPORTCOUNT EVERY 1 HOURS,RATE
table hr.*;
2) 添加pump进程并指明本地文件
add extract pump_so,exttrailsource ./dirdat/et/dd(特别注意抽取进程文件队列所在位置)
3) 添加远程trail文件
add RMTTRAIL ./dirdat/dp1/sd(特别注意参数文件rmttrail位置), EXTRACT PUMP_SO, MEGABYTES 5
说明: 指定远程trail文件
4) 启动pump进程
start extract pump_so
三、 GoldenGate DML同步目标端配置
1. 目标端MGR进程
1) 编辑配置文件
edit params mgr
port 7809
dynamicportlist 7800-8000
autostart er *
autorestart extract *, waitminutes 2, resetminutes 5
lagreporthours 1
laginfominutes 3
lagcriticalminutes 5
purgeoldextracts /u01/app/oracle/ogg/dirdat/rt*, usecheckpoints, minkeepdays 3
2) 启动
start mgr
2. 添加检查表
说明: 当我们在GLOBALS 文件里指定了默认的checkpoint 之后,新的Replicat groups 在创建时会自动使用这个参数,不需要其他指令
1) 编辑全局配置文件
edit params ./GLOBALS
Successfully logged into database.
GGSCI (slave) 2> add checkpointtable ogg.checkpoint
Successfully created checkpoint table OGG.CHECKPOINT.
配置目标端Peplicat进程组
1) 编辑配置文件
edit params repl
REPLICAT rep1
SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1" )
SETENV (ORACLE_SID = "target")
SETENV (NLS_LANG = "AMERICAN_AMERICA.ZHS16GBK")
USERID ogg, PASSWORD ogg
HANDLECOLLISIONS
ASSUMETARGETDEFS
DISCARDFILE ./dirrpt/rep1.dsc ,append ,megabytes 5
--SOURCEDEFS ./dirdef/def.def
DDL INCLUDE MAPPED , OBJTYPE 'TABLE' &
INCLUDE MAPPED OBJTYPE 'INDEX'
MAP hr.T1 ,TARGET hr.T1;
2) 添加复制进程
add replicat rep7,exttrail ./dirdat/dp1/sd(该路径为pump进程定义的远程路径)
3) 启动进程
start repl
4. 可以查看checkpoint状态
su - oracle
sqlplus ogg/ogg
SQL> select tname from tab;
TNAME
-------------------------------------
CHECKPOINT TABLE
CHECKPOINT_LOX TABLE
select * from checkpoint;
注1:ogg_11.1.1.1.2只有CHECKPOINT一张表。
注2:ogg_11.2.x.x.1有CHECKPOINT,CHECKPOINT_LOX两张表。
5. DML配置测试
1) 源端查看表的记录数
conn hr/hr
SQL> select count(*) from t1;
2)执行DML操作后提交
SQL> delete from t1 where rownum < 200;
SQL> select count(*) from t1;
3) 目标端查看
conn hr/hr
SQL> select count(*) from t1;
说明:
到此goldengate DML单向配置已经配置完毕,通过简单的测试示例来进行。
3) 安装DDL对象
SQL> grant dba to ogg;
SQL> @marker_setup 说明: 均指定用户ogg
SQL> @ddl_setup 说明: 11.1.1.2需要手动输入 ogg,INITIALSETUP,yes
SQL> @role_setup
SQL> grant GGS_GGSUSER_ROLE to ogg;
SQL> @ddl_enable
SQL> @marker_status.sql
SQL> @?/rdbms/admin/dbmspool.sql
注1: 执行dbmspool包将在数据库中创建DBMS_SHARED_POOL包,之后ddl_pin包需要用到
注2: 执行ddl_pin.sql通过dbms_shared_pool.keep存储过程将DDLReplication相关对象keep在共享池中,以保证这些对象不要RELOAD,提升性能。
SQL> @ddl_pin.sql ogg
2. 修改extract进程的params文件
# 服务器源端配置
# source端修改extract进程的params文件,添加"ddl include all"参数,重启extract进程
1) 停止eora_t1进程
GGSCI (test) 2> stop extract eora
2) 编辑配置文件
GGSCI (test) 3> edit params eora
extract eora
dynamicresolution
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
userid ogg,password ogg
exttrail /u01/app/oracle/ogg/dirdat/et
ddl include all
ddloptions addtrandata, report
table hr.*;
# 说明:加了两行tranlogoption 与 ddl
3)启动mgr,eora进程
GGSCI (test) 4> start mgr
GGSCI (test) 5> start extract eora
4) 查看eora_t1进程启动情况
GGSCI (test) 6> info extract eora
3. 修改目标端replicat进程的params文件
# 目标服务器配置
# target端修改replicat进程的params文件,
添加"ddlerror default ignore retryop maxretries 3 retrydelay 5" 等参数,重启replicat进程
1) 停止mgr进程
GGSCI (slave) 1> stop mgr
2) 停止repl进程
GGSCI (slave) 1> stop replicat repl
3) 编辑repl配置文件
GGSCI (slave) 1> edit params repl
GGSCI (slave) 2> view params repl
replicat repl
userid ogg, password ogg
assumetargetdefs
reperror default, discard
discardfile /u01/app/oracle/ogg/dirrpt/repl.dsc, append, megabytes 50
dynamicresolution
ddloptions report
ddlerror default ignore retryop maxretries 3 retrydelay 5
ddlerror default discard
ddlerror default ignore retryop
map hr.*, target hr.*;
注: 说明目标端不需要配置DDL include all语句,不然的话,反而会出错。
##Error text [Error code [1031], ORA-01031: insufficient privileges
4) 启动rora_t1进程
GGSCI (slave) 5> info replicat repl
4. 测试
在源端hr用户创建一个表,查看目标端是否成功创建。
create table abc ( id integer , name char(10));
insert into abc values ( 1 , 'abc' );
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。