GoldenGate复制2:linux下oracle到oracle(使用expdp init load)
一.说明:
环境说明:
复制架构:一对一,模拟7*24环境下的实施。
操作系统: Oracle linux 6.3
Oracle: 11.2.0.3.0
GoldenGate: fbo_ggs_Linux_x64_ora11g_64bit.tar
是否支持DDL:否
Init load方式: expdp/impdp (使用flashback_scn)
复制内容:指定schema(erm)下所有表。
|
源端(单实例) |
目标端(单实例) |
hostname |
Vm603 |
OEL63 |
OS |
OEL6.3_64位 |
OEL6.3_64位 |
ip |
192.168.114.174 |
192.168.112.135 |
database |
11g |
11g |
ogg |
fbo_ggs_Linux_x64_ora11g_64bit.tar |
fbo_ggs_Linux_x64_ora11g_64bit.tar |
|
|
|
验证:
由于源库是7*24小时不能停机的库,所以在初始化数据之后,会有新的数据产生,这部分数据通过 expdp/impdp 的flashback_scn解决。
为了检验7*24测试的效果,会在源端创建1个check表,并通过存储过程一直往里插入数据。
操作步骤简介:
1. 源端:正常运行的生产库,生产数据均在1个用户erm下。
2. 目标端:安装数据库软件,并创建相应表空间(略)
3. 两端GoldenGate安装配置
4. 启动验证程序
5. Init load:源端以flashback_scn的方法导出erm下的所有表。并在目标端导入。
6. 目标端使用aftercsn启动replicat进程。
二.实施过程
在实施前假设源端生产环境正常运行,且目标端已经创建了相同的表空间以及用户。
1. GoldenGate安装配置
1---3为安装部分,源端与目标端机器均需要相同操作。
1.配置数据库
源端启用归档:
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 295
Next log sequence to archive 298
Current log sequence 298
源端启用supplementlog:
目标端可以不用打开
SQL> Select supplemental_log_data_minfrom V$database;
SQL> Alterdatabase add supplemental log data;
SQL> alter system switch logfile;
SQL> Select supplemental_log_data_minfrom V$database;
SUPPLEME
--------
YES
由于Oracle中每行记录是由rowid来唯一标识的,但是逻辑复制(如goldengate,stream等)源端和目标端数据库的数据块的结构可能完全不一样,Rowid无法定位。所以使用了supplement log后,就可以精准定位每一条记录,解决了该问题。
源端启用force log:
SQL> Selectname,open_mode,force_logging,supplemental_log_data_min from V$database;
SQL> alter database force logging;
SQL> Select name,open_mode,force_logging,supplemental_log_data_min fromV$database;
两端创建管理用户:
SQL> create user ggs identified by ggsdefault tablespace users;
SQL> grant dba to ggs;
可以不用直接给dba仅限,给仅仅需要的权限,dba用户会带来安装问题。具体参考官方文档。
2.软件解压
[root@OEL63 ~]# su - oracle
[oracle@OEL63 gg11]$ pwd
/u01/oracle/gg11
[oracle@OEL63 gg11]$ tar xvffbo_ggs_Linux_x64_ora11g_64bit.tar
3.环境变量:
新增:
PATH=$ORACLE_BASE/gg11
LD_LIBRARY_PATH=$ORACLE_BASE/gg11:$ORACLE_HOME/lib
4.安装GoldenGate
[oracle@OEL63 gg11]$ pwd
/u01/oracle/gg11
[oracle@OEL63 gg11]$ ggsci
GGSCI (OEL63) 1> create subdirs
5. GLOBALS参数配置
GGSCI (vm603) 2> edit params ./GLOBALS
GGSCHEMA ggs
6.配置mgr进程
> edit paramsmgr
port 7809
> start mgr
> info all
7. 源端add trandata
源端创建验证表。
SQL> conn erm/erm
SQL> create table check_test
2 (id number,
3 name varchar2(30));
GGSCI (vm603) 9> dblogin userid ggs,password ggs
Successfully logged into database.
GGSCI (vm603) 10> add trandata erm.*
这一步时,部分表遇到以下问题:这个问题是缺少主键,可以忽略。
2014-05-09 17:07:19 WARNING OGG-00869 No unique key is defined for tableERM_USER_MAJOR. All viable columns will be used to represent the key, but maynot guarantee uniqueness. KEYCOLS may beused to define the key.
8.源端 extract 进程文件
GGSCI (vm603) 6> edit params ex1
EXTRACT ex1
USERID ggs, password ggs
EXTTRAIL ./dirdat/ex
TABLE erm.*;
GGSCI (vm603) 3> view params ex1
GGSCI (vm603) 4> add extract ex1,tranlog, begin now
EXTRACT added.
GGSCI (vm603) 5> add exttrail./dirdat/ex, extract ex1
EXTTRAIL added.
9.源端pump 进程
GGSCI (vm603) 13> edit params dp1
EXTRACT dp1
USERID ggs,PASSWORD ggs
RMTHOST 192.168.112.135, MGRPORT 7809
RMTTRAIL /u01/oracle/gg11/dirdat/rt
TABLE erm.*;
GGSCI (vm603) 7> add extract dp1exttrailsource ./dirdat/ex
EXTRACT added.
GGSCI (vm603) 8> add rmttrail/u01/oracle/gg11/dirdat/rt, extract dp1
RMTTRAIL added.
10. 目标端CHECKPOINT TABLE
GGSCI (OEL63) 9> edit params ./GLOBALS
GGSCHEMA ggs
CHECKPOINTTABLE ggs.ggs_checkpoint
[oracle@OEL63 gg11]$ ggsci
GGSCI (OEL63) 1> dblogin userid ggs,password ggs
GGSCI (OEL63) 4> add checkpointtable
SQL> conn ggs/ggs
Connected.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ -----------------
GGS_CHECKPOINT TABLE
11.目标端 REPLICAT进程
GGSCI (OEL63) 7> edit params rt1
REPLICAT RT1
USERID ggs,PASSWORD ggs
ASSUMETARGETDEFS
DISCARDFILE ./discards.dsc, PURGE
MAP erm.*, TARGET erm.*;
GGSCI (vm603) 9> addreplicat rt1, exttrail /u01/oracle/gg11/dirdat/rt, checkpointtable ggs.ggs_checkpoint
REPLICAT added.
12.源端创建验证程序:
启动验证程序
declare
begin
for i in 1..100000 loop
insert into check_test values(i,'tan');
commit;
dbms_lock.sleep(1);
end loop;
end;
/
SQL> select * from check_test;
GGSCI (vm603) 7> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT STOPPED DP1 00:00:00 02:00:09
EXTRACT STOPPED EX1 00:00:00 02:02:02
GGSCI (OEL63) 11> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
REPLICAT STOPPED RT1 00:00:00 00:20:40
2. 同步数据
1.源端启动extract,pump进程
GGSCI (vm603) 8> start ex1
GGSCI (vm603) 14> start dp1
GGSCI (vm603) 15> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING DP1 00:00:00 02:03:02
EXTRACT RUNNING EX1 00:00:00 00:00:03
此时先不用启动目标端的replicat进程。
2.使用exp/imp完成init load
用带FLASHBACK_SCN 的expdp/impdp初始化
SQL> select current_scn from V$database;
CURRENT_SCN
-----------
2172822
SQL> create directory backdir as'/home/oracle/backup';
导出导入时不要用当前用户erm,可能会报ERM.SYS_EXPORT_SCHEMA_01相关的错误。
此处用了system
[oracle@vm603 ~]$ expdp system/oracle directory=backdir dumpfile=erm.dmplogfile=gg.log schemas=erm flashback_scn=2172822
[oracle@vm603 backup]$ scp *192.168.112.135:/home/oracle/backup/
[oracle@OEL63 backup]$ impdp system/oracledirectory=backdir dumpfile=erm.dmp logfile=imp_gg.log schemas=erm;
3. 用SCN 启动Replicat
GGSCI (OEL63) 28> start rt1, aftercsn 2172822
Sending START request to MANAGER ...
REPLICAT RT1 starting
GGSCI (OEL63) 29> info all
Program Status Group Lag Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING RT1 00:00:00 00:00:04
4. 在目标库验证:
发现有记录在不断更新。
SQL> select count(*) from check_test;
COUNT(*)
----------
598
SQL> /
COUNT(*)
----------
599
SQL> /
COUNT(*)
----------
600
SQL> /
COUNT(*)
----------
643