OGG几个重要进程介绍:
1、Manager管理进程在两端开启,监控和重启其他进程;分配数据存储和报告错误及事件;
2、Extract进程从日志中抓取并传输到target端事务数据;
3、Server Collector进程在target(接受)端接受数据并写入trail文件;
4、Replicat进程读取trail文件,并应用到traget数据库;
5、trail文件时gg自己抓捕信息的文件,是一个OS文件,存放在./dirdat/下,以X00000命名,N顺序1,2,3…此文件用完可配置参数自动删除。
一、环境准备并安装OGG
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 oracleinstall /u01/app/oracle/ogg
3. 准备OGG环境变量
#源服务器、与目标服务器都要配置
$ vi /home/oracle/.bash_profile
增加如下一行:
export GGATE=$ORACLE_BASE/ogg
生效环境变量
source /home/oracle/.bash_profile
4. 配置日志模式
# 源服务器,目标服务器不用配置(非双向)
1) 查看规档与日志模式
sqlplus / as sysdba
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. 创建OGG用户帐号
1) 源服务器
su - oracle
sqlplus /nolog
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;
2) 目标服务器
su - oracle
sqlplus /nolog
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. 安装OGG软件
(1) 源服务器、与目标服务器都要配置
su - oracle
cd /u01/app/oracle/ogg
./ggsci
GGSCI (test) 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
GGSCI (test) 2> quit
(2) 目标服务器都要配置
su - oracle
cd /u01/app/oracle/ogg
./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
GGSCI (slave) 2> quit
注1:ogg_11.1.1.1.2,ogg_11.2.x.x.1显示创建的文件目录列表结构不一样。
上为ogg11.2版本的创建的内容。
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);
commit;
select count(*) from t1;
----------------------------
COUNT(*)
50315
(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
注: 还可以通过OGG初始化数据加载的方式来实现数据同步。
二、 OGG DML同步源端配置
配置思路:
1) 先配置DML同步
2) 再配置DDL同步
cd /u01/app/oracle/ogg
./ggsci
1. 源MGR进程
1) 编辑主进程组
edit params mgr
port 7809
dynamicportlist 7800-8000
autorestart extract *,retries 5,waitminutes 2,resetminutes 5
说明:
port 指定mgr进程通信端口
dynamicportlist 表示mgr进程可以为源与目的端动态通信指定端口
autorestart extract 表示自动重启extract进程组,每2分钟尝试重启所有进程,重试5次,每5分钟清零。
配置参数后,重启mgr进程生效
2) 启动主管理进程
start mgr
2. 配置Extract进程组
1) 编辑配置文件
edit params eora
extract eora
dynamicresolution
setenv (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
exttrail /u01/app/oracle/ogg/dirdat/et
table hr.*;
说明:
extract eora定义extract进程名字
dynamicresolution
setenv设置环境变量
userid 登录数据库
exttrail指定本地trail文件地址
table 定义同步的表
2) 添加抽取进程
add extract eora, tranlog,begin now
3) 添加本地trail文件
add exttrail /u01/app/oracle/ogg/dirdat/et,extract eora
说明:
创建本地trail文件,主extract进程负责写这部分文件,pump负责把这部分文件传到目标服务器端。
4) 启动服务
start extract eora
3. 配置Pump进程组
1) 编辑配置文件
edit params pump_so
extract pump_so
dynamicresolution
passthru
rmthost 192.168.14.151,mgrport 7809,compress
rmttrail /u01/app/oracle/ogg/dirdat/pt
table hr.*;
2) 添加pump进程
add extract pump_so,exttrailsource /u01/app/oracle/ogg/dirdat/et
3) 添加远程trail文件
add rmttrail /u01/app/oracle/ogg/dirdat/pt,extract pump_so
说明: 指定远程trail文件
4) 启动pump进程
start extract pump_so
三、 OGG DML同步目标端配置
cd /u01/app/oracle/ogg
./ggsci
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.
3. 配置目标端Peplicat进程组
1) 编辑配置文件
edit params repl
replicat repl
userid ogg,password ogg
assumetargetdefs
reperror default,discard
discardfile /u01/app/oracle/ogg/dirrpt/repl.dsc,append,megabytes 50
dynamicresolution
map hr.*, target hr.*;
2) 添加复制进程
add replicat repl,exttrail /u01/app/oracle/ogg/dirdat/pt, CHECKPOINTTABLE ogg.checkpoint
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;
COUNT(*)
----------
49935
2)执行DML操作后提交
SQL> delete from t1 where rownum < 200;
199 rows deleted.
SQL> commit;
SQL> select count(*) from t1;
COUNT(*)
----------
49736
3) 目标端查看
conn hr/hr
SQL> select count(*) from t1;
COUNT(*)
----------
49736
说明:
到此OGG DML单向配置已经配置完毕,通过简单的测试示例来进行。
四、 OGG DDL同步配置
1. 支持DDL复制运行脚本
# 服务器源端配置
1) 指定数据库模式
$ ./ggsci
GGSCI (test) 1> edit param ./GLOBALS
GGSCI (test) 2> view param ./GLOBALS
ggschema ogg
GGSCI (test) 3> stop mgr
2) oralce 10gR2数据库需要关闭回收站。
su - oracle
cd /u01/app/oracle/ogg
sqlplus / as sysdba;
alter system set recyclebin=off scope=both;
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
注1: 执行dbmspool包将在数据库中创建DBMS_SHARED_POOL包,之后ddl_pin包需要用到
SQL> @?/rdbms/admin/dbmspool.sql
Package created.
Grant succeeded.
View created.
Package body created.
注2: 执行ddl_pin.sql通过dbms_shared_pool.keep存储过程将DDLReplication相关对象keep在共享池中,以保证这些对象不要RELOAD,提升性能。
SQL> @ddl_pin.sql ogg
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
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
Sending STOP request to REPLICAT RORA_T1 ... Request processed.
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' );