有时候ogg两端数据不一致,且数据量较大,手工修改比较复杂的情况下,我们需要对这些表进行初始化。初始化的大概思路是:
停止两端OGG
如果业务不可以停很长时间,就需要配置目标端进程,暂停这些问题表的同步。待新数据导入后,再次停启进程
源端通过SCN号备份问题表,传送到目标端还原
修改目标端进程配置,从SCN开始恢复
开启OGG进程
源端简陋配置:
GGSCI (db1) 9> infoall
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
useridogg,password ogg
rmthost192.168.25.101,mgrport 7809
rmttrail /u01/goldengate/dirdat/fp
ddl include mappedobjname db_fpzx.*;
table db_fpzx.*;
目标端简陋配置:
GGSCI (db2) 6> infoall
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,PASSWORDogg
discardfile/u01/goldengate/discard/rep2_discard.dsc, append, megabytes 10
DDL INCLUDE MAPPED
DDLERROR DEFAULTIGNORE RETRYOP
ASSUMETARGETDEFS
map db_fpzx.*,target db_fpzx.*;
我们对db_fpzx.liuliu 这张表进行初始化
SQL> select *from liuliu;
ID | AGE | NAME | EEE | WWW |
1 | liu | liuliu222 | ||
2 | liu | liuliu222 | ||
3 | liu | 123 | liuliu333 | |
4 | liu | liuliu444 | ||
5 | liu | liuliu555 | ||
6 | liu | liuliu666 | ||
7 | liu | liuliu222 | ||
8 | shshshs | liuliu222 | ||
9 | liu | liuliu222 |
9 rowsselected.
我们将目标端中的数据删除,再在源端插入几条数据,是不会报错的,但是此时两端数据已经不一致了,需要对目标端进行初始化。一般来说初始化是在你不知道丢失哪些数据的情况下进行,如果差个两三条你知道的数据,直接在目标端进行插入或修改更快。
SQL> delete from liuliu;
9 rows deleted.
SQL> commit;
Commit complete.
SQL> select *from liuliu;
no rows selected
1、停止两端OGG进程
源端查询SCN号:
SQL> selectdbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
729295
2、要求实时性的处理
在数据实时性要求较高的系统,首先确定问题表,然后只在目标端配置文件中将问题表剔除:
MAPEXCLUDE DB_FPZX.LIULIU;
然后启动进程即可。
3、源端通过SCN号备份问题表,传送到目标端还原
备份
exp db_fpzx/fpzx file=/u01/backup/db_fpzx20161129.dmp tables=(liuliu) log=/u01/backup/db_fpzx20161129.log flashback_scn=729295
传输
scp db_fpzx20161129.dmp oracle@192.168.25.101:/u01/backup
还原
imp system/oracle file=/u01/backup/db_fpzx20161129.dmp fromuser=db_fpzx touser=db_fpzx tables=liuliu ignore=y
4、修改目标端进程配置,从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.*;
~
~5、启动OGG,查询两端状态