OGG 单表初始化操作步骤
有时候ogg两端数据不一致,且数据量较大,手工修改比较复杂的情况下,我们需要对这些表进行初始化。初始化的大概思路是:
1. 停止两端OGG
2. 如果业务不可以停很长时间,就需要配置目标端进程,暂停这些问题表的同步。待新数据导入后,再次停启进程
3. 源端通过SCN号备份问题表,传送到目标端还原
4. 修改目标端进程配置,从SCN开始恢复
5. 开启OGG进程
源端简陋配置:
GGSCI (db1) 9> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
EXTRACT RUNNING EXTFPZX 00:00:00 00:00:05
GGSCI (db1) 10> view params EXTFPZX
extract extfpzx
userid ogg,password ogg
rmthost 192.168.25.101,mgrport 7809
rmttrail /u01/goldengate/dirdat/fp
ddl include mapped objname db_fpzx.*;
table db_fpzx.*;
目标端简陋配置:
GGSCI (db2) 6> info all
Program Status Group Lag at Chkpt Time Since Chkpt
MANAGER RUNNING
REPLICAT RUNNING REPFPZX 00:00:00 00:00:01
GGSCI (db2) 7> view params REPFPZX
REPLICAT repfpzx
USERID ogg,PASSWORD ogg
discardfile /u01/goldengate/discard/rep2_discard.dsc, append, megabytes 10
DDL INCLUDE MAPPED
DDLERROR DEFAULT IGNORE RETRYOP
ASSUMETARGETDEFS
map db_fpzx.*, target db_fpzx.*;
我们对”liuliu”这张表进行初始化
SQL> select * from liuliu;
ID AGE NAME EEE WWW
---------- ---------- -------------------- -------------------- --------------------
2 liu liuliu222
3 liu 123 liuliu333
4 liu liuliu444
5 liu liuliu555
6 liu liuliu666
1 liu liuliu222
7 liu liuliu222
8 shshshs liuliu222
9 liu liuliu222
9 rows selected.
我们将目标端中的数据删除,再在源端插入几条数据,是不会报错的,但是此时两端数据已经不一致了,需要对目标端进行初始化。一般来说初始化是在你不知道丢失哪些数据的情况下进行,如果差个两三条你知道的数据,直接在目标端进行插入或修改更快。
SQL> delete from liuliu;
9 rows deleted.
SQL> commit;
Commit complete.
SQL> select * from liuliu;
no rows selected
1、停止两端OGG进程
源端查询SCN号:
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
729295
2、源端通过SCN号备份问题表,传送到目标端还原
l 备份
exp db_fpzx/fpzx file=/u01/backup/db_fpzx20161129.dmp tables=(liuliu) log=/u01/backup/db_fpzx20161129.log flashback_scn=729295
l 传输
scp db_fpzx20161129.dmp oracle@192.168.25.101:/u01/backup
l 还原
imp system/oracle file=/u01/backup/db_fpzx20161129.dmp fromuser=db_fpzx touser=db_fpzx tables=liuliu ignore=y
3、修改目标端进程配置,从SCN开始还原
GGSCI (db2) 44> edit params REPFPZX
REPLICAT repfpzx
USERID ogg,PASSWORD ogg
discardfile /u01/goldengate/discard/rep2_discard.dsc, append, megabytes 10
DDL INCLUDE MAPPED
DDLERROR DEFAULT IGNORE RETRYOP
ASSUMETARGETDEFS
map db_fpzx.liuliu, target db_fpzx.liuliu, filter (@GETENV("transaction","csn") >729295);
map db_fpzx.*,target db_fpzx.*;
~
~4、启动OGG,查询两端状态