1. OGG PUMP和REPLICAT进程的拆分与合并

1.1. OGG 拆分PUMP和REPLICAT进程

1.1.1. 停止extarct进程

GGSCI (cndba) 4> stop ext1

Sending STOP request to EXTRACT EXT1 ...
Request processed.

1.1.2. 检查extact进程的checkpoint信息

GGSCI (cndba) 5> info ext1,showch
记录下其Write Checkpoint信息中的sequence和RBA值,如下:
Write Checkpoint #1

  GGS Log Trail

  Current Checkpoint (current write position):
    Sequence #: 29
    RBA: 1351
    Timestamp: 2018-06-12 11:10:24.327370
    Extract Trail: ./dirdat/et

1.1.3. 检查pump进程的checkpoint信息

GGSCI (cndba) 9> info pump1,showch
若pump进程的Current Checkpoint信息中的sequence和RBA值与step 2得到的值相等,则说明goldengate抓取的信息都已被传送到了target服务器上,可继续执行下一步骤。否则,等待并重复运行该命令。
  Current Checkpoint (position of last record read in the data source):
    Sequence #: 29
    RBA: 1351
    Timestamp: 2018-06-12 10:26:36.000000
    Extract Trail: ./dirdat/et
记录其Write Checkpoint信息中的sequence和RBA值,如下:
Write Checkpoint #1

  GGS Log Trail

  Current Checkpoint (current write position):
    Sequence #: 25
    RBA: 1754
    Timestamp: 2018-06-12 11:14:52.629268
    Extract Trail: ./dirdat/et

1.1.4. 检查replicat进程的checkpoint信息

GGSCI (cndba) 29> info rep1,showch
  Current Checkpoint (position of last record read in the data source):
    Sequence #: 25
    RBA: 1754
    Timestamp: 2018-06-12 10:26:36.628558
    Extract Trail: ./dirdat/et
若replicat进程的Current Checkpoint信息中的sequence和RBA值与step 3中得到的Write Checkpoint信息相等,则说明goldengate抓取的信息都已被apply到target 数据库,可继续执行下一步骤。否则,等待并重复运行该命令。

1.1.5. 停止pump进程和replicat进程

--源端操作
GGSCI (cndba) 10> stop pump1

Sending STOP request to EXTRACT PUMP1 ...
Request processed.
--目标端操作
GGSCI (cndba) 30> stop rep1

Sending STOP request to REPLICAT REP1 ...
Request processed.

1.1.6. 创建两个新的pump进程

add extract pump01,exttrailsource ./dirdat/et,begin now
add rmttrail ./dirdat/p1,extract pump01
add extract pump02,exttrailsource ./dirdat/et,begin now
add rmttrail ./dirdat/p2,extract pump02

1.1.7. 添加pump进程配置文件

这两个新的参数文件与原有的参数文件的主要区别是将其中的复制表按负载均分为了两部分,分别放在单独的参数文件中。
GGSCI (cndba) 15> edit params pump01
GGSCI (cndba) 18> view params pump01

EXTRACT pump01
RMTHOST 192.168.1.86, MGRPORT 7809
RMTTRAIL ./dirdat/p1
PASSTHRU
DYNAMICRESOLUTION
TABLE test.test;

GGSCI (cndba) 16> edit params pump02
GGSCI (cndba) 19> view params pump02

EXTRACT pump02
RMTHOST 192.168.1.86, MGRPORT 7809
RMTTRAIL ./dirdat/p2
PASSTHRU
DYNAMICRESOLUTION
TABLE test.test2;

1.1.8. 修改新建pump进程的read checkpoint信息

根据step 3中得到的read checkpoint信息修改新建pump进程的checkpoint信息,让其从旧pump进程停止的位置开始抓取新的信息
GGSCI (cndba) 26> ALTER EXTRACT pump01, EXTSEQNO 25, EXTRBA 1754
EXTRACT altered.

GGSCI (cndba) 27> ALTER EXTRACT pump02, EXTSEQNO 25, EXTRBA 1754
EXTRACT altered.

1.1.9. 创建两个新的replicat 进程

GGSCI (cndba) 31> add replicat rep01, exttrail ./dirdat/p1, checkpointtable ogg.checkpoint
REPLICAT added.

GGSCI (cndba) 32> add replicat rep02, exttrail ./dirdat/p2, checkpointtable ogg.checkpoint
REPLICAT added.
备份并删除traget服务器上/u01/app/oracle/ogg/dirdat/目录下原有的以p1,p2开头的trail file文件

1.1.10. 配置replicat 参数文件

GGSCI (cndba) 39> edit params rep01
GGSCI (cndba) 38> view params rep01

REPLICAT rep01
--setenv (ORACLE_SID=cndba)
--SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1")
USERID ogg,PASSWORD ogg
ASSUMETARGETDEFS
--HANDLECOLLISIONS
REPERROR (DEFAULT, DISCARD)
DDLERROR DEFAULT DISCARD
DDLOPTIONS REPORT
DISCARDFILE ./dirrpt/repr01.dsc,append,megabytes 100
--HANDLECOLLISIONS
MAP test.test, TARGET test.test;

GGSCI (cndba) 39> edit params rep02
GGSCI (cndba) 39> view params rep02

REPLICAT rep02
--setenv (ORACLE_SID=cndba)
--SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1")
USERID ogg,PASSWORD ogg
ASSUMETARGETDEFS
--HANDLECOLLISIONS
REPERROR (DEFAULT, DISCARD)
DDLERROR DEFAULT DISCARD
DDLOPTIONS REPORT
DISCARDFILE ./dirrpt/repr02.dsc,append,megabytes 100
--HANDLECOLLISIONS
MAP test.test2, TARGET test.test2;

1.1.11. 启动pump 进程

GGSCI (cndba) 48> start pump01

Sending START request to MANAGER ...
EXTRACT PUMP01 starting


GGSCI (cndba) 49> start pump02

Sending START request to MANAGER ...
EXTRACT PUMP02 starting
GGSCI (cndba) 51> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     RUNNING     EXT1        00:00:00      00:00:09    
EXTRACT     RUNNING     PUMP01      00:00:00      00:37:53    
EXTRACT     RUNNING     PUMP02      00:00:00      00:37:47    
EXTRACT     STOPPED     PUMP1       00:00:00      00:51:55

1.1.12. 启动extract 进程

GGSCI (cndba) 33> start ext1

Sending START request to MANAGER ...
EXTRACT EXT1 starting

1.1.13. 启动replicat进程

GGSCI (cndba) 40> start rep01

Sending START request to MANAGER ...
REPLICAT REP01 starting


GGSCI (cndba) 41> start rep02

Sending START request to MANAGER ...
REPLICAT REP02 starting

GGSCI (cndba) 42> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    RUNNING     REP01       00:00:00      00:00:07    
REPLICAT    RUNNING     REP02       00:00:00      00:00:03    
REPLICAT    STOPPED     REP1        00:00:00      00:48:33

1.1.14. 删除旧的pump进程和replicat进程

--删除旧的pump进程
GGSCI (cndba) 53> delete pump1
GGSCI (cndba) 78> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     RUNNING     EXT1        00:00:00      00:00:09    
EXTRACT     RUNNING     PUMP01      00:00:00      00:00:04    
EXTRACT     RUNNING     PUMP02      00:00:00      00:00:04

--删除旧的replicat进程
GGSCI (cndba) 45> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (cndba) 46> delete rep1
Deleted REPLICAT REP1.


GGSCI (cndba) 47> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    RUNNING     REP01       00:00:00      00:00:05    
REPLICAT    RUNNING     REP02       00:00:00      00:00:09

1.1.15. 测试

--源端插入数据
SQL>  insert into test values(51,'test'); 

1 row created.

SQL> insert into test2 values(4,'test');

1 row created.

SQL> commit;

Commit complete.
SQL> select count(*) from test;

  COUNT(*)
----------
 42
--目标端查看数据同步
SQL> select count(*) from test; 

  COUNT(*)
----------
 42

SQL> select * from test2;

 ID NAME
---------- --------
  1 zhangsan
  3 test
  4 test

1.2. OGG 合并PUMP和REPLICAT进程

1.2.1. 停止extract 进程

GGSCI (cndba) 81> stop ext1

Sending STOP request to EXTRACT EXT1 ...
Request processed.

1.2.2. 检查extract进程的checkpoint信息

GGSCI (cndba) 82> info ext1,showch
记录下其Write Checkpoint信息中的sequence和RBA值,如下:
Write Checkpoint #1

  GGS Log Trail

  Current Checkpoint (current write position):
    Sequence #: 30
    RBA: 5634
    Timestamp: 2018-06-12 13:38:50.221917
    Extract Trail: ./dirdat/et

1.2.3. 检查pump进程的checkpoint信息

若pump进程的Current Checkpoint信息中的sequence和RBA值与step 2得到的值相等,则说明goldengate抓取的信息都已被传送到了target服务器上,可继续执行下一步骤。否则,等待并重复运行该命令。
GGSCI (cndba) 83> info pump01,showch
  Current Checkpoint (position of last record read in the data source):
    Sequence #: 30
    RBA: 5634
    Timestamp: 2018-06-12 13:35:55.000000
    Extract Trail: ./dirdat/et
记录下其Write Checkpoint信息中的sequence和RBA值,如下:
Write Checkpoint #1

  GGS Log Trail

  Current Checkpoint (current write position):
    Sequence #: 0
    RBA: 5499
    Timestamp: 2018-06-12 13:42:02.894776
    Extract Trail: ./dirdat/p1

GGSCI (cndba) 84> info pump02,showch
  Current Checkpoint (position of last record read in the data source):
    Sequence #: 30
    RBA: 5634
    Timestamp: 2018-06-12 13:35:55.000000
    Extract Trail: ./dirdat/et
记录下其Write Checkpoint信息中的sequence和RBA值,如下:
Write Checkpoint #1

  GGS Log Trail

  Current Checkpoint (current write position):
    Sequence #: 0
    RBA: 1193
    Timestamp: 2018-06-12 13:42:35.595896
    Extract Trail: ./dirdat/p2

1.2.4. 检查replicat进程的checkpoint信息

若replicat进程的Current Checkpoint信息中的sequence和RBA值与step 3中得到的Write Checkpoint信息相等,则说明goldengate抓取的信息都已被apply到target 数据库,可继续执行下一步骤。否则,等待并重复运行该命令。
GGSCI (cndba) 50> info rep01,showch
  Current Checkpoint (position of last record read in the data source):
    Sequence #: 0
    RBA: 5499
    Timestamp: 2018-06-12 13:35:55.536888
Extract Trail: ./dirdat/p1

GGSCI (cndba) 51> info rep02,showch
  Current Checkpoint (position of last record read in the data source):
    Sequence #: 0
    RBA: 1193
    Timestamp: 2018-06-12 12:26:44.611904
    Extract Trail: ./dirdat/p2

1.2.5. 停止pump进程和replicat进程

--源端停止pump进程
GGSCI (cndba) 85> stop pump01

Sending STOP request to EXTRACT PUMP01 ...
Request processed.


GGSCI (cndba) 86> stop pump02

Sending STOP request to EXTRACT PUMP02 ...
Request processed.

--目标端停止replicat进程
GGSCI (cndba) 52> stop rep01

Sending STOP request to REPLICAT REP01 ...
Request processed.


GGSCI (cndba) 53> stop rep02

Sending STOP request to REPLICAT REP02 ...
Request processed.

1.2.6. 创建新的pump进程

add extract pump1,exttrailsource ./dirdat/et
add rmttrail ./dirdat/et,extract pump1

1.2.7. 修改新建pump进程的read checkpoint信息

根据step 3中得到的read checkpoint信息修改新建pump进程的checkpoint信息,让其从旧pump进程停止的位置开始抓取新的信息
ALTER EXTRACT pump1, EXTSEQNO 30, EXTRBA 5634

1.2.8. 添加pump1进程配置

GGSCI (cndba) 87> edit params pump1
GGSCI (cndba) 88> view params pump1

EXTRACT pump1
RMTHOST 192.168.1.86, MGRPORT 7809
RMTTRAIL ./dirdat/et
PASSTHRU
DYNAMICRESOLUTION
TABLE test.*;

1.2.9. 创建新的replicat进程

GGSCI (cndba) 31> add replicat rep1, exttrail ./dirdat/et, checkpointtable ogg.checkpoint
REPLICAT added.
备份并删除traget服务器上/u01/app/oracle/ogg/dirdat/目录下原有的以et,et开头的trail file文件

1.2.10. 配置replicat 参数文件

GGSCI (cndba) 39> edit params rep01
GGSCI (cndba) 38> view params rep01

REPLICAT rep01
--setenv (ORACLE_SID=cndba)
--SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1")
USERID ogg,PASSWORD ogg
ASSUMETARGETDEFS
--HANDLECOLLISIONS
REPERROR (DEFAULT, DISCARD)
DDLERROR DEFAULT DISCARD
DDLOPTIONS REPORT
DISCARDFILE ./dirrpt/repr01.dsc,append,megabytes 100
--HANDLECOLLISIONS
MAP test.test, TARGET test.test;

1.2.11. 启动extract进程

GGSCI (cndba) 89> start ext1

Sending START request to MANAGER ...
EXTRACT EXT1 starting

1.2.12. 启动新的pump进程和replicat进程

--启动pump进程
GGSCI (cndba) 96> start pump1

Sending START request to MANAGER ...
EXTRACT PUMP1 starting
--启动replicat进程
GGSCI (cndba) 56> start rep1

Sending START request to MANAGER ...
REPLICAT REP1 starting

1.2.13. 删除旧的pump进程

GGSCI (cndba) 100> delete pump01
GGSCI (cndba) 100> delete pump02

1.2.14. 删除旧的replicat进程

GGSCI (cndba) 60> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (cndba) 61> delete rep01
Deleted REPLICAT REP01.

GGSCI (cndba) 62> delete rep02     
Deleted REPLICAT REP02.

1.2.15. 测试

--源端插入数据
SQL> select * from test;

no rows selected

SQL> insert into test values(1,'test');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test2;

 ID NAME
---------- --------
  1 zhangsan
  3 test
  4 test

SQL> insert into test2 values(5,'test');
1 row created.
SQL> commit;
Commit complete.
--目标端查看数据
SQL> select * from test;

 ID NAME
---------- --------
  1 test

SQL> select * from test2;

 ID NAME
---------- --------
  5 test
  1 zhangsan
  3 test
  4 test