Oracle 快照及 dblink使用 (兩臺服務(wù)器數(shù)據(jù)同步)
--名詞說明:源——被同步的數(shù)據(jù)庫
--??????????目的——要同步到的數(shù)據(jù)庫
/*一、創(chuàng)建dblink:*/
--1、在目的數(shù)據(jù)庫上,創(chuàng)建dblin
drop public?database?link?wc;
Create?public
database?link?wc
Connect?to?test?identified?by?xiongwei?using?'toby';
select * from dba_db_links;
select * from a@wc;
--源數(shù)據(jù)庫的用戶名、密碼、服務(wù)器名k
/*二、創(chuàng)建快照:*/
--1、在源和目的數(shù)據(jù)庫上同時執(zhí)行一下語句,創(chuàng)建要被同步的表
drop?table tb_anson;
create?table tb_anson(c1?varchar2(12));
alter?table tb_anson add?constraint?pk_anson primary?key?(C1);
--2、在目的數(shù)據(jù)庫上,測試dblink
select?*?from tb_anson@dblink_anson;
select?*?from tb_anson;
--3、在目的數(shù)據(jù)庫上,創(chuàng)建要同步表的快照日志
Create?snapshot?log?on?tb_anson;
--4、創(chuàng)建快照,快照(被同步(源)數(shù)據(jù)庫服務(wù)必須啟動)
Create?snapshot?sn_anson as?select?*?from?tb_anson@dblink_anson;
--5、設(shè)置快照刷新時間
Alter?snapshot anson? refresh?fast?Start?with?sysdate+1/24*60?next?sysdate+10/24*60;
--oracle自動在1分鐘后進行第一次快速刷新,以后每隔10分鐘快速刷新一次
Alter?snapshot anson? refresh?complete?Start?with?sysdate+30/24*60*60?next?sysdate+1;
--oracle自動在30鈔后進行第一次完全刷新,以后每隔1天完全刷新一次
--6、手動刷新快照
begin
dbms_refresh.refresh('"CS"."SN_ANSON"');
end;
eg:
drop public?database link dblink_e3nfjj;
Create public
database link dblink_e3nfjj
Connect to e3nfjj identified by e3nfjj using 'ORCL10_192.168.20.26';
create table template as
select * from template@dblink_e3nfjj;
本用戶登錄進去的一定要能連接 'ORCL10_192.168.20.26' 這個Oracle 的SID.
posted on 2009-04-09 21:23 tobyxiong 閱讀(484) 評論(0) 編輯 收藏 所屬分類: DATABASES