使用dbms_rectifier_diff解决高级复制中的数据冲突问题作者:eygle出处:http://blog.eygle.com日期:january 19, 2005
« oracle基于时间点的恢复 | blog首页 | 关于oracle的冲突解决机制的研究 »
很多时候在高级复制中可能存在数据冲突和不一致现象。
oracle提供的dbms_rectifier_diff包可以用于解决该冲突。
以下通过实例来说明一下该package的用法。
1.创建复制组及复制对象
sql> execute dbms_repcat.create_master_repgroup('rep_tt');
pl/sql procedure successfully completed
sql> select gname,master,status from dba_repgroup;
gname master status
------------------------------ ------ ---------
rep_tt y quiesced
sql> execute dbms_repcat.create_master_repobject(sname=>'hawa',oname=>'test', type=>'table',use_existing_object=>true,gname=>'rep_tt',copy_rows=>false);
pl/sql procedure successfully completed
sql>
sql> execute dbms_repcat.generate_replication_support('hawa','test','table');
pl/sql procedure successfully completed
sql> select gname, master, status from dba_repgroup;
gname master status
------------------------------ ------ ---------
rep_tt y quiesced
sql> select * from dba_repobject;
sname oname type status generation_status id object_comment gname min_communication replication_trigger_exists internal_package_exists group_owner nested_table
------------------------------ ------------------------------ ---------------- ---------- ----------------- ---------- -------------------------------------------------------------------------------- -----------------
hawa test table valid generated 8620 rep_tt y y y public n
hawa test$rp package valid 8641 system-generated: replication rep_tt public
hawa test$rp package body valid 8677 system-generated: replication rep_tt public
3 rows selected
sql>
sql> execute dbms_repcat.add_master_database(gname=>'rep_tt',master=>'authaa.coolyoung.com.cn',use_existing_objects=>true, copy_rows=>false, propagation_mode => 'synchronous');
pl/sql procedure successfully completed
sql> execute dbms_repcat.resume_master_activity('rep_tt',true);
pl/sql procedure successfully completed
sql> select * from dba_repgroup;
sname master status schema_comment gname fname rpc_processing_disabled owner
-------- ------------------ ---- ------ ---- ---- -----------------------------------------------
rep_tt y normal rep_tt n public
2.创建保存冲突数据的数据表
a.missing_rows表用以保存冲突行
sql> create table hawa.missing_rows_test
2 as
3 select * from hawa.test where 1=0;
table created
b.用于保存缺失行位置及rowid
sql> create table hawa.missing_location_test (
2 present varchar2(128),
3 absent varchar2(128),
4 r_id rowid);
table created
3.使用dbms_rectifier_diff.differences查找缺失记录
sql> begin dbms_rectifier_diff.differences(
2 sname1 =>'hawa',
3 oname1 =>'test',
4 reference_site =>'avatar.coolyoung.com.cn',
5 sname2 =>'hawa',
6 oname2 =>'test',
7 comparison_site =>'authaa.coolyoung.com.cn',
8 where_clause =>null,
9 column_list =>null,
10 missing_rows_sname =>'hawa',
11 missing_rows_oname1 =>'missing_rows_test',
12 missing_rows_oname2 =>'missing_location_test',
13 missing_rows_site =>'avatar.coolyoung.com.cn',
14 max_missing =>500,
15 commit_rows =>100
16 );
17 end;
18 /
pl/sql procedure successfully completed
冲突记录被保存在我们创建的指定表中
sql> select count(*) from hawa.missing_rows_test;
count(*)
----------
172
共有172条差异记录
sql> select count(*) from hawa.test;
count(*)
----------
548
sql> select count(*) from [email protected];
count(*)
----------
376
sql> select count(*) from hawa.missing_location_test;
count(*)
----------
172
4.使用dbms_rectifier_diff.rectify进行数据整合
首先需要注意的是:
rectify过程使用differences产生的数据进行数据调整。
在第一个表中存在,在第二个表中不存在的数据将被插入第二张表。
在第二个表中存在,在第一个个表中不存在的数据将被从第二张表中删除。
另外,在这个数据纠正过程中,你可以使用dbms_repcat.suspend_master_activity将复制组暂时挂起。
这样便于保证数据完整性。
但这不是必须的,如果复制一直激活,可能会有新的冲突出现。
sql> begin dbms_rectifier_diff.rectify( 2 sname1 =>'hawa', 3 oname1 =>'test', 4 reference_site =>'avatar.coolyoung.com.cn', 5 sname2 =>'hawa', 6 oname2 =>'test', 7 comparison_site =>'authaa.coolyoung.com.cn', 8 column_list =>null, 9 missing_rows_sname =>'hawa', 10 missing_rows_oname1 =>'missing_rows_test', 11 missing_rows_oname2 =>'missing_location_test', 12 missing_rows_site =>'avatar.coolyoung.com.cn', 13 commit_rows =>100 14 ); 15 end; 16 /pl/sql procedure successfully completedsql> select count(*) from [email protected]; count(*)---------- 548sql> select count(*) from hawa.test; count(*)---------- 548
数据矫正完成以后,数据会自动从missing_rows表中删除。
sql> select count(*) from hawa.missing_rows_test;
count(*)
----------
0
sql>
网站运营seo文章大全提供全面的站长运营经验及seo技术!