OGG synchronous test cases with and without primary key table's primary key

1. OGG synchronous test cases with and without primary key table's primary key

Environment Description: OGG version 11.2.1.0.1, the source test, there is a primary key, test3 table without a primary key, trail end of the target file is not deleted.

1.1 Test insert operation source

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

1 row created.

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

1 row created.

SQL> insert into test3 values(2,'test');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test3;   

 ID NAME
---------- --------------------------------
  1 test
  1 test
  2 test
--目标端查看数据
SQL> select * from test3;

 ID NAME
---------- --------------------------------
  1 test
  1 test
  2 test
--查看源端日志
2018-06-19 10:24:54  WARNING OGG-00869  Oracle GoldenGate Capture for Oracle, ext1.prm:  No unique key is defined for table 'TEST3'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.
数据虽然被同步过来但是日志有警告,警告表没有主键。

1.2 Test delete operation source

--源端删除数据
SQL> delete from test3 where id=1;

3 rows deleted.

SQL> commit;

Commit complete.

SQL> select * from test3;

 ID NAME
---------- --------------------------------
  2 test
--目标端查看结果
SQL> select * from test3;

 ID NAME
---------- --------------------------------
  2 test
删除操作数据也被同步过来

1.3. Testing source update operations

--源端更新数据
SQL> update test3 set name='test3' where id=1;

3 rows updated.

SQL> commit;

Commit complete.

SQL> select * from test3;

 ID NAME
---------- --------------------------------
  2 test
  1 test3
  1 test3
  1 test3
--目标端查看数据
SQL> select * from test3;

 ID NAME
---------- --------------------------------
  2 test
  1 test
  1 test
  1 test
通过测试可以看到源端的update操作,对目标端的操作是随机性的不能保证数据的一致性。

1.4. Simulation target-side data reinitialization

1.4.1. A scene

测试目标端的表被truncate,然后让replicat从trail文件号0 ,或者指定文件号抽取数据来还原目标表数据。
1)停止目标端replicat
GGSCI (cndba) 9> stop rep1

Sending STOP request to REPLICAT REP1 ...
Request processed.
2)truncate 目标端测试表
test 表有主键,test3没主键
SQL> truncate table test;

Table truncated.

SQL> truncate table test3;

Table truncated.
3)初始化replicat 从trail 文件号0 开始抽取数据
注意从指定的trail文件号抽取数据,要保证次trail文件在dirdat目录下存在,否则进程会中止。
GGSCI (cndba) 10> alter replicat rep1,extseqno 0,extrba 0
REPLICAT altered.

GGSCI (cndba) 11> start rep1

Sending START request to MANAGER ...
REPLICAT REP1 starting
4)查看目标端表数据
可以看到有主键的表数据同步正常,无主键的表同步不正常,多出一条数据,原因是因为没有主键,无法做唯一性校验,数据就会出现不确定性的结果。
SQL> select * from test;

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

SQL> select * from test3;

 ID NAME
---------- --------------------------------
  2 test
  1 test
  1 test
  1 test3
     1 test3

1.4.2. Scene II

测试目标端的表数据不做修改,然后让replicat从trail文件号0 ,或者指定文件号抽取数据来还原目标表数据。
1)停止目标端replicat
GGSCI (cndba) 9> stop rep1

Sending STOP request to REPLICAT REP1 ...
Request processed.
2)初始化replicat 从trail 文件号0 开始抽取数据
注意从指定的trail文件号抽取数据,要保证次trail文件在dirdat目录下存在,否则进程会中止。
GGSCI (cndba) 10> alter replicat rep1,extseqno 0,extrba 0
REPLICAT altered.

GGSCI (cndba) 11> start rep1

Sending START request to MANAGER ...
REPLICAT REP1 starting
3)查看目标端表数据
可以看到有主键的表数据同步正常,无主键的表同步不正常,出现重复数据,原因是因为没有主键,无法做唯一性校验,数据就会出现不确定性的结果。
SQL> select * from test;

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

SQL> select * from test3;

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

10 rows selected.

1.4.3. Scene Three

测试目标端的表被误删除,然后让replicat从trail文件号0 ,或者指定文件号抽取数据来还原目标表数据。
1)停止目标端replicat
GGSCI (cndba) 9> stop rep1

Sending STOP request to REPLICAT REP1 ...
Request processed.
2)目标端删除一条数据
test 表有主键
SQL> delete from test where id=2;

1 row deleted.

SQL> commit;

Commit complete.
3)初始化replicat 从trail 文件号0 开始抽取数据
注意从指定的trail文件号抽取数据,要保证次trail文件在dirdat目录下存在,否则进程会中止。
GGSCI (cndba) 10> alter replicat rep1,extseqno 0,extrba 0
REPLICAT altered.

GGSCI (cndba) 11> start rep1

Sending START request to MANAGER ...
REPLICAT REP1 starting
4)查看目标端表数据
可以看到有主键的表数据同步正常,数据被还原,前提要保证trail数量可以保证能恢复和源端数据一致性
SQL> select * from test;

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

Summary : Test we can know, the problem OGG appear to have a primary key synchronization does table, no primary key can not guarantee data consistency, it is recommended that the table needs to be synchronized must add a primary key to prevent the source, target-side data inconsistent.

Guess you like

Origin blog.csdn.net/leo__1990/article/details/91776744