建立测试环境:
原库: oracle 10.2.0.464位 for win2003
目的库:oracle 11.2.0.1 64位 for linux RAC.
原库的test01用户传到目标库的test01用户中,
配置好流环境后,进行如下的测试。
配置好流环境后,进行如下的测试。
原库test01用户登录系统后,建立t7表,并增加id=2的记录。
SQL> create table t7 as select * from t1;
表已创建。
SQL> insert into t7 values (2);
已创建 1 行。
SQL> commit;
提交完成。
查看目标库.test01用户下的记录已经正常接收。
SQL> select * from test01.t6;
ID
----------
1
2
原库做更新测试:
SQL> select * from test01.t6;
ID
----------
1
2
原库做更新测试:
SQL> update t7 set id=id+1;
已更新2行。
SQL> commit;
提交完成。
SQL>
目标库查询时,是没有记录的,查询错误记录表,发现ORA-01422错误。
SQL> col apply_name format a13;
SQL> col SOURCE_TRANSACTION_ID format a13;
SQL> select apply_name,LOCAL_TRANSACTION_ID,SOURCE_TRANSACTION_ID,ERROR_MESSAGE from dba_apply_error;
APPLY_NAME LOCAL_TRANSACTI SOURCE_TRANSA ERROR_MESSAGE
------------- ---------------------- ------------- ---------------------------------------------------------
APPLY_STANDY 4.5.308567 2.2.624 ORA-01422: exact fetch returns more than requested number of rows
更新的记录不唯一造成的。
SQL> col SOURCE_TRANSACTION_ID format a13;
SQL> select apply_name,LOCAL_TRANSACTION_ID,SOURCE_TRANSACTION_ID,ERROR_MESSAGE from dba_apply_error;
APPLY_NAME LOCAL_TRANSACTI SOURCE_TRANSA ERROR_MESSAGE
------------- ---------------------- ------------- ---------------------------------------------------------
APPLY_STANDY 4.5.308567 2.2.624 ORA-01422: exact fetch returns more than requested number of rows
更新的记录不唯一造成的。
SQL> SELECT apply_name, apply_captured, status,ERROR_MESSAGE FROM dba_apply;
APPLY_NAME APPLY_CAPTURED STATUS ERROR_MESSAGE
------------- -------------- -------- ---------------------------------------------------
APPLY_STANDY YES ABORTED ORA-26714: User error encountered while applying
SQL> alter table t7 add constraint cons_id primary key (id);
表已更改。
重新启动目标库应用。
SQL> exec dbms_apply_adm.start_apply('APPLY_STANDY');
PL/SQL procedure successfully completed
SQL> exec dbms_apply_adm.start_apply('APPLY_STANDY');
PL/SQL procedure successfully completed
SQL> SELECT apply_name, apply_captured, status,ERROR_MESSAGE FROM dba_apply;
APPLY_NAME APPLY_CAPTURED STATUS ERROR_MESSAGE
------------- -------------- -------- --------------------------------------------------
APPLY_STANDY YES ENABLED
查看目标库,CONS_ID索引已经接收到
SQL> select INDEX_NAME from DBA_indexes where owner='TEST01';
INDEX_NAME
------------------------------
P_ID
CONS_ID
再次查看错误记录信息,原先的错误还有。
SQL> select apply_name,LOCAL_TRANSACTION_ID,SOURCE_TRANSACTION_ID,ERROR_MESSAGE from dba_apply_error;
APPLY_NAME LOCAL_TRANSACT SOURCE_TRANSA ERROR_MESSAGE
------------- ---------------- ------------- ---------------------------------------------------------------
APPLY_STANDY 4.5.308567 2.2.624 ORA-01422: exact fetch returns more than requested number of rows
SQL> select apply_name,LOCAL_TRANSACTION_ID,SOURCE_TRANSACTION_ID,ERROR_MESSAGE from dba_apply_error;
APPLY_NAME LOCAL_TRANSACT SOURCE_TRANSA ERROR_MESSAGE
------------- ---------------- ------------- ---------------------------------------------------------------
APPLY_STANDY 4.5.308567 2.2.624 ORA-01422: exact fetch returns more than requested number of rows
可以打印这个错误信息号,看到old,new值确实是我刚才修改前的数值
SQL> EXEC print_transaction('4.5.308567');
----- Local Transaction ID: 4.5.308567
----- Source Database: LISHZ
----Error Number: 1422
----Message Text: ORA-01422: exact fetch returns more than requested number of rows
--message: 1
type name: SYS.LCR$_ROW_RECORD
source database: LISHZ
owner: TEST01
object: T7
is tag null: Y
command_type: UPDATE
old(1): ID
1
new(1): ID
2
--message: 2
type name: SYS.LCR$_ROW_RECORD
source database: LISHZ
owner: TEST01
object: T7
is tag null: Y
command_type: UPDATE
old(1): ID
2
new(1): ID
3
PL/SQL procedure successfully completed
再次执行原先的事务,
SQL>
SQL> BEGIN
2 DBMS_APPLY_ADM.EXECUTE_ERROR(
3 LOCAL_TRANSACTION_ID => '4.5.308567',
4 EXECUTE_AS_USER => FALSE);
5 END;
6 /
PL/SQL procedure successfully completed
查看错误记录表,已经都正常了。
SQL> select apply_name,LOCAL_TRANSACTION_ID,SOURCE_TRANSACTION_ID,ERROR_MESSAGE from dba_apply_error;
APPLY_NAME LOCAL_TRANSACTION_ID SOURCE_TRANSA ERROR_MESSAGE
------------- ---------------------- ------------- ------------------------
type name: SYS.LCR$_ROW_RECORD
source database: LISHZ
owner: TEST01
object: T7
is tag null: Y
command_type: UPDATE
old(1): ID
1
new(1): ID
2
--message: 2
type name: SYS.LCR$_ROW_RECORD
source database: LISHZ
owner: TEST01
object: T7
is tag null: Y
command_type: UPDATE
old(1): ID
2
new(1): ID
3
PL/SQL procedure successfully completed
再次执行原先的事务,
SQL>
SQL> BEGIN
2 DBMS_APPLY_ADM.EXECUTE_ERROR(
3 LOCAL_TRANSACTION_ID => '4.5.308567',
4 EXECUTE_AS_USER => FALSE);
5 END;
6 /
PL/SQL procedure successfully completed
查看错误记录表,已经都正常了。
SQL> select apply_name,LOCAL_TRANSACTION_ID,SOURCE_TRANSACTION_ID,ERROR_MESSAGE from dba_apply_error;
APPLY_NAME LOCAL_TRANSACTION_ID SOURCE_TRANSA ERROR_MESSAGE
------------- ---------------------- ------------- ------------------------
再次查看t7表,记录已经和原库同步了。
SQL> select * from test01.t7;
ID
----------
2
3
本文转自 gjm008 51CTO博客,原文链接:http://blog.51cto.com/gaoshan/383534,如需转载请自行联系原作者