同步处理部分数据
背景
- 最近在项目上发现两个分库进行数据同步时部分内容同步存在问题.
- 最简单的方法是导表,但是害怕有其他关联信息异常, 所以同事想到了dblink的方式.
- 这里简单整理一下 同事用到的方法 作为总结 备忘.
建立数据库连接
create database link test connect to yourname identified by "yourpassword"
using '(DESCRIPTION =(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = someip)
(PORT = 1521)))
(CONNECT_DATA =(SERVICE_NAME = servicename)))';
记性备份,以及添加未同步的数据
select * from sometable@fzzk where id not in(select id from sometable)
create table somtable_1206bak as select * from somtable
insert into sometable select * from sometable@fzzk where id not in(select id from sometable)
升级不一致的数据
merge into somtable a
using sometable@fzzk b
on (a.id=b.id)
when matched then
update set a.treeinfo_path = b.treeinfo_path