ogg的安装配置 配置双向同步(含DDL)
第一部分 先配置单向同步(含DDL)
一 源端安装GoldenGate
创建用户
创建目录
mkdir -p /opt/ogg
chmod -R 777 /opt/ogg
chown -R oracle:oinstall /opt/ogg
ogg用户
useradd -g oinstall -G dba ggate
解压软件
设置环境变量
配置goldengate用户变量
su – ggate
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=prm
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/u01/app/oracle/ggate
export GGATE=/opt/ogg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$PATH:$ORACLE_HOME/bin:$GGATE
安装GoldenGate
图形化安装方法中,在software location部分选择环境变量中GGATE的值,不过要注意给GGATE目录适当的权限;
Database Location部分就是ORACLE_HOME的值。
二 目标端安装GoldenGate
创建用户
创建目录
mkdir -p /opt/ogg
chmod -R 755 /opt/ogg
chown -R oracle:oinstall /opt/ogg
ogg用户
useradd -g oinstall -G dba ggate
解压软件
设置环境变量
配置goldengate用户变量
su – ggate
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=prm
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/u01/app/oracle/ggate
export GGATE=/opt/ogg
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$PATH:$ORACLE_HOME/bin:$GGATE
安装GoldenGate
图形化安装方法中,在software location部分选择环境变量中GGATE的值,不过要注意给GGATE目录适当的权限;
Database Location部分就是ORACLE_HOME的值。
三 配置源端数据库
开启归档
开启归档
修改之前 创建参数文件做备份
create pfile='/home/oracle/initdemo.ora' from spfile;
alter system set log_archive_dest='/arch/prm' scope=spfile; --修改归档的路径
---alter system set db_recovery_file_dest='' scope=spfile; --关闭闪回
shutdown immediate;
startup mount;
alter database archivelog;
archive log list;
alter database open;
设置数据库force logging
实际生产应用中,最好同时打开ORACLE的强制日志模式,以防止源数据库因直接路径加载忽略redo生成而导致这部分数据无法同步:
SQL> select force_logging from v$database;
SQL> Alter database force logging;
开启最小附加日志(DDL的话好开启数据库级别)
Oracle数据库需要开启归档日志,并开启最小附加日志模式。
SQL> select supplemental_log_data_min from v$database; --查看是否开启了最小附加日志模式
SQL> alter database add supplemental log data; --开启最小附加日志模式
千万不要小看这步日志设置,其实在GoldenGate的配置中,这步是最容易出错的环节。如果开启DDL复制做冗灾备份,最好直接在数据库级别打开补全日志:
SQL> alter database add supplemental log data (primary key,unique,foreign key) columns;
检查一下,全是YES就OK了(整个数据库级别补全)
SQL> select supplemental_log_data_min,
supplemental_log_data_pk,supplemental_log_data_ui from v$database;
源库关闭回收站
SQL> show parameter recyclebin
SQL> alter system set recyclebin=off scope=spfile;
SQL>shutdown immediate;
SQL>startup;
SQL> show parameter recyclebin
UNDO设置
alter system set undo_retention=86400;
创建goldengate用户并且授权
创建表空间、用户、赋予dba权限
create tablespace ogg datafile '/u01/app/oracle/oradata/prm/ogg01.dbf' size 1024M;
create user ggate identified by ggate default tablespace ogg temporary tablespace temp;
grant connect,resource,unlimited tablespace to ggate;
grant connect,resource,dba to ggate;
grant execute on utl_file to ggate;
grant select any dictionary,select any table to ggate;
grant alter any table to ggate;
grant flashback any table to ggate;
grant execute on DBMS_FLASHBACK to ggate;
grant insert any table to ggate;
grant delete any table to ggate;
grant update any table to ggate;
运行DDL同步需要的脚本
cd $GGATE
@marker_setup.sql;
@ddl_setup.sql;
@role_setup.sql;
grant GGS_GGSUSER_ROLE to ggate;
@ddl_enable.sql;
安装性能优化包。
SQL> @?/rdbms/admin/dbmspool
ddl_pin将触发器用到的plsql包放进内存中
cd $GGATE
SQL> @ddl_pin ggate
添加传输表【transdata】
光开启最小附加日志模式还不够,还需要打开表级的补全日志,可以在GoldenGate中使用add trandata命令强制重做日志记录主键值,以保证在目标端能成功复制:
GGSCI> dblogin userid ggate,password ggate --GoldenGate中登录OARCLE数据库
GGSCI>add trandata sender.* --表名可以使用通配符
GGSCI> add trandata coss3.per_test,nokey,cols(sampletime, objectid)
SQL> alter table <tablename> add supplemental log data (primary key) columns;
GGSCI(node1) 1> dblogin userid ogg,password oracle
GGSCI(node1) 2> add trandata SCOTT.DEPT
四 配置源端进程组
GGSCI(node1) 1> edit param mgr
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
--PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
--PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
GGSCI (node1) > edit params ./GLOBALS
Program Status Group Lag at Chkpt Time Since Chkpt
GGSCI(node1)> add extract extnd, tranlog, begin now
GGSCI (GOLDENGATE1) 4> edit params extnd
SETENV (NLS_LANG = "AMERICAN_AMERICA.UTF8")
SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/dbhome_1")
DISCARDFILE ./dirdat/extnd.dsc,APPEND,MEGABYTES 5
TRANLOGOPTIONS ALTARCHIVELOGDEST /arch/prm
TRANLOGOPTIONS ALTARCHIVEDLOGFORMAT %t_%s_%r.dbf
FETCHOPTIONS, USESNAPSHOT, NOUSELATESTVERSION, MISSINGROW REPORT
WARNLONGTRANS 1H, CHECKINTERVAL 5M
添加该extract对应的trail文件,用来存储抽取的数据。单个文件大小设置为100MB
GGSCI(node1)> add exttrail ./dirdat/nd, extract extnd, megabytes 100
GGSCI(node1)>add extract dpend, exttrailsource ./dirdat/nd, begin now
GGSCI(node1)> edit params dpend
SETENV (NLS_LANG = "AMERICAN_AMERICA.UTF8")
RMTHOST 192.168.80.166, MGRPORT 8809
DISCARDFILE ./dirdat/dpend.dsc,APPEND,MEGABYTES 5
GGSCI(node1)> add rmttrail ./dirdat/nd, extract dpend, megabytes 100
五 配置目标数据库【含源端业务新增数据模拟】
create tablespace ogg datafile '/u01/app/oracle/oradata/prm/ogg01.dbf' size 1024M;
create user ggate identified by ggate default tablespace ogg temporary tablespace temp;
grant connect,resource,unlimited tablespace to ggate;
grant connect,resource,dba to ggate;
grant execute on utl_file to ggate;
grant select any dictionary,select any table to ggate;
grant alter any table to ggate;
grant flashback any table to ggate;
grant execute on DBMS_FLASHBACK to ggate;
grant insert any table to ggate;
grant delete any table to ggate;
grant update any table to ggate;
grant GGS_GGSUSER_ROLE to ggate;
六 配置目标端进程组
GGSCI(node2) 1> edit param mgr
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
--PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
--PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
GGSCI (node2)> edit params ./GLOBALS
CHECKPOINTTABLE ggate.chkpoint
GGSCI (node2)> dblogin userid ggate, password ggate
Successfully logged into database.
GGSCI (node2)> add checkpointtable ggate.chkpoint
Successfully created checkpoint table goldengate.chkpoint.
GGSCI (node2)> add replicat repnd, exttrail ./dirdat/nd, checkpointtable ggate.chkpoint
GGSCI (node2)> edit params repnd
DISCARDFILE ./dirrpt/repnd.dsc,APPEND,MEGABYTES 5
DDLERROR DEFAULT DISCARD RETRYOP MAXRETRIES 5 RETRYDELAY 20
MAP sender.* , TARGET sender.* ;
七 启动进程进行数据库同步
八 数据同步测试
create table t1 (id number CONSTRAINT id_nn NOT NULL,
insert into t1 values (1,'aaa');
insert into t1 values (2,'bbb');
insert into t1 values (3,'ccc');
insert into t1 values (4,'ddd');
create table t2 (id number CONSTRAINT id_nm NOT NULL,
insert into t2 values (1,'word');
insert into t2 values (2,'now');
insert into t2 values (3,'values');
insert into t2 values (4,'beijing');
insert into t1 values (5,'eee')
insert into t1 values (6,'fff')
insert into t1 values (7,'ggg')
create table t3 as select * from t1 where 1=0;
create table t4 as select * from t1;
九 环境说明
十 各程序组配置名称及参数【成功后记录】
GGSCI(node1) 1> edit param mgr
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
--PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
--PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
GGSCI (node1) > edit params ./GLOBALS
GGSCI(node1)> add extract extnd, tranlog, begin now
GGSCI (GOLDENGATE1) 4> edit params extnd
SETENV (NLS_LANG = "AMERICAN_AMERICA.UTF8")
SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/dbhome_1")
DISCARDFILE ./dirdat/extnd.dsc,APPEND,MEGABYTES 5
TRANLOGOPTIONS ALTARCHIVELOGDEST /arch/prm
TRANLOGOPTIONS ALTARCHIVEDLOGFORMAT %t_%s_%r.dbf
FETCHOPTIONS, USESNAPSHOT, NOUSELATESTVERSION, MISSINGROW REPORT
WARNLONGTRANS 1H, CHECKINTERVAL 5M
添加该extract对应的trail文件,用来存储抽取的数据。单个文件大小设置为100MB
GGSCI(node1)> add exttrail ./dirdat/nd, extract extnd, megabytes 100
GGSCI(node1)>add extract dpend, exttrailsource ./dirdat/nd, begin now
GGSCI(node1)> edit params dpend
SETENV (NLS_LANG = "AMERICAN_AMERICA.UTF8")
RMTHOST 192.168.80.166, MGRPORT 8809
DISCARDFILE ./dirdat/dpend.dsc,APPEND,MEGABYTES 5
GGSCI(node1)> add rmttrail ./dirdat/nd, extract dpend, megabytes 100
GGSCI(node2) 1> edit param mgr
AUTORESTART EXTRACT *,RETRIES 5,WAITMINUTES 3
PURGEOLDEXTRACTS ./dirdat/*,usecheckpoints, minkeepdays 3
--PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
--PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5, FREQUENCYMINUTES 30
GGSCI (node2)> edit params ./GLOBALS
CHECKPOINTTABLE ggate.chkpoint
GGSCI (node2)> add replicat repnd, exttrail ./dirdat/nd, checkpointtable ggate.chkpoint
GGSCI (node2)> edit params repnd
DISCARDFILE ./dirrpt/repnd.dsc,APPEND,MEGABYTES 5
DDLERROR DEFAULT DISCARD RETRYOP MAXRETRIES 5 RETRYDELAY 20
MAP sender.* , TARGET sender.* ;
第二部分配置双向同步(含DDL)
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
因为现源端数据库是之前目标端数据库rman初始化过来的,所以这部分忽略
PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPFILES 10
PURGEOLDEXTRACTS ./dirdat/*, USECHECKPOINTS, MINKEEPFILES 10
GGSCI (node1)> edit params ./GLOBALS
CHECKPOINTTABLE ggate.chkpoint
GGSCI (node1)> dblogin userid ggate, password ggate
GGSCI (node1)> add checkpointtable ggate.chkpoint
add extract extd2, tranlog, begin now
GGSCI (node1)> edit params extd2
SETENV (NLS_LANG = "AMERICAN_AMERICA.UTF8")
SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/dbhome_1")
TRANLOGOPTIONS EXCLUDEUSER ggate
DISCARDFILE ./dirdat/extd2.dsc,APPEND,MEGABYTES 5
TRANLOGOPTIONS ALTARCHIVELOGDEST /arch/prm
TRANLOGOPTIONS ALTARCHIVEDLOGFORMAT %t_%s_%r.dbf
FETCHOPTIONS, USESNAPSHOT, NOUSELATESTVERSION, MISSINGROW REPORT
WARNLONGTRANS 1H, CHECKINTERVAL 5M
添加该extract对应的trail文件,用来存储抽取的数据。单个文件大小设置为100MB
GGSCI (node2)> add exttrail ./dirdat/et,extract extd2,megabytes 100
GGSCI (node1)>edit param EXTND
TRANLOGOPTIONS EXCLUDEUSER ggate
TRANLOGOPTIONS ALTARCHIVELOGDEST /arch/prm
TRANLOGOPTIONS ALTARCHIVEDLOGFORMAT %t_%s_%r.dbf
GGSCI (node2)>add extract dpnd2, exttrailsource ./dirdat/et, begin now
GGSCI (node2)> edit params dpnd2
SETENV (NLS_LANG = "AMERICAN_AMERICA.UTF8")
RMTHOST 192.168.80.160, MGRPORT 8809
DISCARDFILE ./dirdat/dpnd2.dsc,APPEND,MEGABYTES 5
GGSCI (node2)> add rmttrail ./dirdat/et, extract dpnd2, megabytes 100
GGSCI (node1)> add replicat repnd2, exttrail ./dirdat/et, checkpointtable ggate.chkpoint
GGSCI (node1)> edit params repnd2
DISCARDFILE ./dirrpt/repnd2.dsc,APPEND,MEGABYTES 5
DDLERROR DEFAULT DISCARD RETRYOP MAXRETRIES 5 RETRYDELAY 20
MAP sender.* , TARGET sender.* ;
GGSCI (node2)> dblogin userid ggate, password ggate
GGSCI (node2)> add trandata sender.*
SQL> select current_scn from v$database;
start repnd2, aftercsn 1297690
insert into t1 values (6,'fff');
insert into t1 values (7,'ggg');
insert into t1 values (7,'hhh');
insert into t1 values (8,'eee');
insert into t1 values (9,'fff');
insert into t1 values (10,'ggg');
create table t5 as select * from t1 where 1=0;
create table t4 as select * from t1;
create tablespace test01 datafile '/u01/app/oracle/oradata/prm/test01.dbf' size 5m;
create table t6 as select * from t1;
drop tablespace test01 including contents and datafiles;
十一 附件
(2)选择一个数据库schema存放支持DDL的GoldenGate对象,运行相应创建脚本。
SQL>alter system set recyclebin=off scope=both;
GGSCHEMA ddw --标明支持DDL的GG对象存放在哪个schema下
首先需要命令行进入GG安装目录下,然后再运行sqlplus执行脚本,如果不进入目录下脚本执行会报错(应该是由于GG脚本中子脚本嵌套使用相对路径的问题所造成)。
SQL>@marker_setup.sql --提示输入目标schema
SQL>@ddl_setup.sql --提示输入目标schema,输入initialsetup最后输入yes
SQL>grant GGS_GGSUSER_ROLE to ddw; --不进行该步赋权后面起进程会报错
(4)修改提取进程和复制进程的配置文件,分别加入ddl include all属性。
此时repl必须指定assumetargetdefs属性,这表明只有两边数据库结构一致的情况下才可以启用DDL复制。另外,开启DDL同步不能再只映射单表了,对整个模式下的对象都有效。
在实际测试中,由于我在同一个数据库中进行映射,映射表结构不一致,导致进程报了一系列的错误。这个时候需要把通过脚本创建的GG对象中的数据清空,安装目录下只提供了清除对象的脚本,可以如下操作:
SQL>@ddl_disable.sql --首先使DDL触发器失效