同步處理部分數據
背景
- 最近在項目上發現兩個分庫進行數據同步時部分內容同步存在問題.
- 最簡單的方法是導表,但是害怕有其他關聯信息異常, 所以同事想到了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