物化視圖實現 Oracle 資料庫表雙向同步

來源:互聯網
上載者:User

Oracle 資料庫跨庫同步表有很多種方式可以實現, 比如觸發器, Materialized View(MV), Stream, Goldengate 等

Materialized View(物化視圖)是包括一個查詢結果的資料庫對像, 它是遠端資料的的本機複本, 或者用來產生基於資料表求和的匯總表. 物化視圖儲存基於遠端資料表的資料, 也可以稱為快照. 這個基本上就說出了物化視圖的本質, 它是一組查詢的結果, 這樣勢必為將來再次需要這組資料時大大提高查詢效能.下面就介紹使用 Materialized View + Job 的方式來雙向同步表,具體步驟如下:

1. 在來源資料庫 A 和目標資料庫 B 上分別建立 table     

create table test 

    id varchar2(10) not null primary key, 
    name varchar2(20), 
    status varchar2(1), 
    updatedate date 

2. 在資料庫上分別建立 dblink

create database link dblink_to_B 
connect to "userid" identified by "password" 
using '(DESCRIPTION = 
    (ADDRESS_LIST = 
        (ADDRESS = (PROTOCOL = TCP)(HOST = "ipaddress")(PORT = 1521)) 
    ) 
    (CONNECT_DATA = 
        (SERVICE_NAME = "SID") 
    ) 
)'; 
 
create database link dblink_to_A 
connect to "userid" identified by "password" 
using '(DESCRIPTION = 
    (ADDRESS_LIST = 
        (ADDRESS = (PROTOCOL = TCP)(HOST = "ipaddress")(PORT = 1521)) 
    ) 
    (CONNECT_DATA = 
        (SERVICE_NAME = "SID") 
    ) 
)'; 

3. 在來源資料庫 A 上建立 Materialized View 以及 Materialized view log

create materialized view log on test with rowid 
   
create materialized view mv_test refresh fast on demand with rowid 
as select * from <A href="mailto:test@dblink_to_B">test@dblink_to_B</A>

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.