参考网上资料配置stream 流环境的update 冲突方式时,应用进程总是会中断,折腾了好久才解决,但总觉得处理办法很别扭,先把过程记下来。
单向流环境配置好以后,增加update 冲突解决方式;
SQL> declare
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='ID';
5 cols(2):='VNAME';
6 cols(3):='QTY';
7 cols(4):='VADDR';
8 cols(5):='VSEX';
9 dbms_apply_adm.set_update_conflict_handler(
10 object_name => 'HZ.T1',
11 method_name => 'overwrite',
12 resolution_column => 'VNAME',
13 column_list => cols);
14 end;
15 /
PL/SQL procedure successfully completed
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='ID';
5 cols(2):='VNAME';
6 cols(3):='QTY';
7 cols(4):='VADDR';
8 cols(5):='VSEX';
9 dbms_apply_adm.set_update_conflict_handler(
10 object_name => 'HZ.T1',
11 method_name => 'overwrite',
12 resolution_column => 'VNAME',
13 column_list => cols);
14 end;
15 /
PL/SQL procedure successfully completed
目标库修改记录2的vname值为111,如下:
目标库T1的记录。
SQL> SELECT * FROM HZ.T1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 guangzhou 100 111 333
2 111 200 111 333
SQL> SELECT * FROM HZ.T1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 guangzhou 100 111 333
2 111 200 111 333
原库更新T1表记录2的vname 值为333,如下:
SQL> SELECT * FROM T1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 guangzhou 100 111 333
2 333 200 111 333
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 guangzhou 100 111 333
2 333 200 111 333
这时目标库的应用进程中止了。
SQL> select status from dba_apply;
STATUS
--------
ABORTED
STATUS
--------
ABORTED
应用错误记录表显示
SQL> select * from dba_apply_error;
APPLY_NAME LOCAL_TRANSACTION_ID ERROR_MESSAGE
------------ ---------------------- -------------------------------------------------------------------------------- -
APPLY_STANDY 5.13.848 ORA-26786: A row with key ("ID") = (2) exists but has conflicting column(s) "VNA
APPLY_NAME LOCAL_TRANSACTION_ID ERROR_MESSAGE
------------ ---------------------- -------------------------------------------------------------------------------- -
APPLY_STANDY 5.13.848 ORA-26786: A row with key ("ID") = (2) exists but has conflicting column(s) "VNA
3.执行过程,提示错误,
SQL> EXEC DBMS_APPLY_ADM.execute_error('5.13.848');
begin DBMS_APPLY_ADM.execute_error('5.13.848'); end;
ORA-23460: 列 "QTY" 的值丢失, 在解析方法 "OVERWRITE" 中用于 "HZ"."T1"."REP_UPDATE"
ORA-26786: 键为 ("ID") = (2) 的行存在, 但具有冲突列 "VNAME" (在表 HZ.T1 中)
ORA-01403: 未找到任何数据
ORA-06512: 在 "SYS.DBMS_APPLY_ERROR", line 151
ORA-06512: 在 "SYS.DBMS_APPLY_ERROR", line 265
ORA-06512: 在 "SYS.DBMS_APPLY_ADM", line 467
ORA-06512: 在 line 2
SQL> EXEC DBMS_APPLY_ADM.execute_error('5.13.848');
begin DBMS_APPLY_ADM.execute_error('5.13.848'); end;
ORA-23460: 列 "QTY" 的值丢失, 在解析方法 "OVERWRITE" 中用于 "HZ"."T1"."REP_UPDATE"
ORA-26786: 键为 ("ID") = (2) 的行存在, 但具有冲突列 "VNAME" (在表 HZ.T1 中)
ORA-01403: 未找到任何数据
ORA-06512: 在 "SYS.DBMS_APPLY_ERROR", line 151
ORA-06512: 在 "SYS.DBMS_APPLY_ERROR", line 265
ORA-06512: 在 "SYS.DBMS_APPLY_ADM", line 467
ORA-06512: 在 line 2
4.删除现有的冲突定义
SQL> declare
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='ID';
5 cols(2):='VNAME';
6 cols(3):='QTY';
7 cols(4):='VADDR';
8 cols(5):='VSEX';
9 dbms_apply_adm.set_update_conflict_handler(
10 object_name => 'HZ.T1',
11 method_name => null,
12 resolution_column => 'VNAME',
13 column_list => cols);
14 end;
15 /
PL/SQL procedure successfully completed
5.重新定义新的冲突方式,字段值列出vname字段看效果
SQL>
SQL> declare
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='VNAME';
5 dbms_apply_adm.set_update_conflict_handler(
6 object_name => 'HZ.T1',
7 method_name => 'overwrite',
8 resolution_column => 'VNAME',
9 column_list => cols);
10 end;
11 /
PL/SQL procedure successfully completed
6.再次执行错误的事务号,执行成功了。
SQL> EXEC DBMS_APPLY_ADM.execute_error('5.13.848');
PL/SQL procedure successfully completed
7.查看目标库的记录,已经更新了
SQL> select * from hz.t1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 guangzhou 100 111 333
2 333 200 111 333
继续试验:
1.目标库更新:
SQL> update hz.t1 set vaddr='guangzhou',qty=1 where id=1;
1 row updated
SQL> commit;
Commit complete
SQL> SELECT * FROM hz.T1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 666 1 guangzhou 333
2 333 200 111 333
2.原库更新
SQL> update hz.t1 set vaddr='aaa' where id=1;
1 row updated
SQL> commit;
Commit complete
SQL> update hz.t1 set vaddr='aaa' where id=1;
1 row updated
SQL> commit;
Commit complete
3.应用出错.
SQL> select status from dba_apply;
STATUS
--------
ABORTED
SQL> select ERROR_NUMBER,ERROR_MESSAGE from dba_apply_error;
ERROR_NUMBER ERROR_MESSAGE
------------ --------------------------------------------------------------------------------
26786 ORA-26786: A row with key ("ID") = (1) exists but has conflicting column(s) "VAD
------------ --------------------------------------------------------------------------------
26786 ORA-26786: A row with key ("ID") = (1) exists but has conflicting column(s) "VAD
SQL> exec dbms_apply_adm.execute_error('2.12.797');
begin dbms_apply_adm.execute_error('2.12.797'); end;
ORA-26786: 键为 ("ID") = (1) 的行存在, 但具有冲突列 "VADDR" (在表 HZ.T1 中)
ORA-01403: 未找到任何数据
ORA-06512: 在 "SYS.DBMS_APPLY_ERROR", line 151
ORA-06512: 在 "SYS.DBMS_APPLY_ERROR", line 265
ORA-06512: 在 "SYS.DBMS_APPLY_ADM", line 467
ORA-06512: 在 line 2
可以看到刚才只定义的vname 字段的冲突显然不能满足现在的情况。尝试一并加上其它字段的方式,执行错误事务号时还是报错。
4.只好把所有更新的字段一个个写入冲突方式中,
SQL> declare
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='QTY'; --定义QTY的冲突方式
5 dbms_apply_adm.set_update_conflict_handler(
6 object_name => 'HZ.T1',
7 method_name => 'overwrite',
8 resolution_column => 'QTY',
9 column_list => cols);
10 end;
11 /
PL/SQL procedure successfully completed
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='QTY'; --定义QTY的冲突方式
5 dbms_apply_adm.set_update_conflict_handler(
6 object_name => 'HZ.T1',
7 method_name => 'overwrite',
8 resolution_column => 'QTY',
9 column_list => cols);
10 end;
11 /
PL/SQL procedure successfully completed
SQL> declare
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='VADDR'; --定义VADDR的冲突方式
5 dbms_apply_adm.set_update_conflict_handler(
6 object_name => 'HZ.T1',
7 method_name => 'overwrite',
8 resolution_column => 'VADDR',
9 column_list => cols);
10 end;
11 /
PL/SQL procedure successfully completed
2 cols dbms_utility.name_array;
3 begin
4 cols(1):='VADDR'; --定义VADDR的冲突方式
5 dbms_apply_adm.set_update_conflict_handler(
6 object_name => 'HZ.T1',
7 method_name => 'overwrite',
8 resolution_column => 'VADDR',
9 column_list => cols);
10 end;
11 /
PL/SQL procedure successfully completed
5.再次执行成功.
SQL> exec dbms_apply_adm.execute_error('2.12.797');
PL/SQL procedure successfully completed
SQL> exec dbms_apply_adm.execute_error('2.12.797');
PL/SQL procedure successfully completed
6.查看目标库记录,和原库的一样了。
SQL> SELECT * FROM hz.T1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 666 1 aaa 333
2 333 200 111 333
SQL> SELECT * FROM hz.T1;
ID VNAME QTY VADDR VSEX
---------- -------------------- ---------- ---------- ----------
1 666 1 aaa 333
2 333 200 111 333
7. dba_apply_conflict_columns 表的记录。
SQL> select OBJECT_OWNER,OBJECT_NAME,METHOD_NAME,RESOLUTION_COLUMN,COLUMN_NAME from dba_apply_conflict_columns WHERE OBJECT_NAME='T1';
OBJECT_OWNER OBJECT_NAME METHOD_NAME RESOLUTION_COLUMN COLUMN_NAME
------------- ------------- ------------- ----------------------- ------------------------------
HZ T1 OVERWRITE QTY QTY
HZ T1 OVERWRITE VADDR VADDR
HZ T1 OVERWRITE VNAME VNAME
本文转自 gjm008 51CTO博客,原文链接:http://blog.51cto.com/gaoshan/406537,如需转载请自行联系原作者