Oracle:跨數據庫跨版本跨平臺,進行高級複製

物化視圖複製的設置
主站點:prod
物化視圖站點:emrep
主機名:dbserver
複製用戶:hr
檢查初始化參數
SQL> connect sys/oracle @prod as sysdba ;
已鏈接。
SQL> show parameter global_names ;
NAME TYPE VALUE
 
global_names boolean TRUE
SQL> show parameter job;
NAME TYPE VALUE
 
job_queue_PRocesses integer 20
SQL> select * from global_name ;
GLOBAL_NAME
 
prod
SQL>
SQL> connect sys/oracle@emrep as sysdba ;
已鏈接。
SQL> show parameter global_names ;
NAME TYPE VALUE
 
global_names boolean TRUE
SQL> show parameter job;
NAME TYPE VALUE
 
job_queue_processes integer 10
SQL> select * from global_name ;
GLOBAL_NAME
 
emrep
SQL>
檢查全局數據庫名稱
SQL> connect hr/hr@emrep ;
已鏈接。
SQL> select * from hr.employees @prod ;
...
SQL>
SQL> connect system/oracle@emrep;
已鏈接。
SQL> select owner,db_link from all_db_links ;
OWNER DB_LINK
 
SYS prod
PUBLIC prod
SQL> connect system/oracle@prod;
已鏈接。
SQL> select owner,db_link from all_db_links ;
OWNER DB_LINK
 
SYS emrep
PUBLIC emrep
SQL>
創建主體站點
SQL> connect system/oracle@prod ;
已鏈接。
SQL>
--創建複製管理用戶repadmin 並受權
CREATE USER repadmin IDENTIFIED BY repadmin;
BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (username => 'repadmin');
END;
/
GRANT COMMENT ANY TABLE TO repadmin;
GRANT LOCK ANY TABLE TO repadmin;
GRANT SELECT ANY DICTIONARY TO repadmin;
--註冊傳播用戶並受權
BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (username => 'repadmin');
END;
/
--註冊接收用戶
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'repadmin',
privilege_type => 'receiver',
list_of_gnames => NULL);
END;
/
--創建物化視圖站點複製管理員的代理用戶
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'repadmin',
privilege_type => 'proxy_snapadmin',
list_of_gnames => NULL);
END;
/
GRANT CREATE session TO repadmin;
GRANT SELECT ANY TABLE TO repadmin;
--以複製管理員身份登錄到主站點
SQL> CONNECT repadmin/repadmin@prod ;
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (
next_date => SYSDATE,
interval => 'SYSDATE + 1/24',
delay_seconds => 0);
END;
/
commit;
設置物化視圖站點
SQL> connect system/whoami@emrep ;
--創建物化視圖管理員,並受權
CREATE USER mvadmin IDENTIFIED BY mvadmin;
BEGIN
DBMS_REPCAT_ADMIN.GRANT_ADMIN_ANY_SCHEMA (
username => 'mvadmin');
END;
/
GRANT COMMENT ANY TABLE TO mvadmin;
GRANT LOCK ANY TABLE TO mvadmin;
GRANT SELECT ANY DICTIONARY TO mvadmin;
--創建傳播者,並受權
BEGIN
DBMS_DEFER_SYS.REGISTER_PROPAGATOR (username => 'mvadmin');
END;
/
--創建刷新者,並受權,這裏使用mvadmin 用戶刷新物化視圖
GRANT CREATE SESSION TO mvadmin;
GRANT ALTER ANY MATERIALIZED VIEW TO mvadmin;
--註冊接受者
BEGIN
DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP (
username => 'mvadmin',
privilege_type => 'receiver',
list_of_gnames => NULL);
END;
/
--創建PUBLIC 數據庫鏈
CREATE PUBLIC DATABASE LINK db001 USING 'prod';
SQL> CONNECT mvadmin/mvadmin@emrep;
已鏈接。
SQL>CREATE DATABASE LINK prod CONNECT TO repadmin IDENTIFIED BY repadmin;
--創建到主站點上覆制管理員的數據庫鏈
--以傳播者身份登錄物化視圖站點
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PURGE (
next_date => SYSDATE,
interval => 'SYSDATE + 1/24',
delay_seconds => 0,
rollback_segment => '');
END;
/
--設置將修改推入到主站點的job
BEGIN
DBMS_DEFER_SYS.SCHEDULE_PUSH (
destination => 'prod',
interval => 'SYSDATE + 1/24',
next_date => SYSDATE,
stop_on_error => FALSE,
delay_seconds => 0,
parallelism => 0);
END;
/
commit;
創建主體組
--以複製管理員身份登錄複製站點
CONNECT repadmin/repadmin@prod ;
--創建名爲rep_test 的複製組
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPGROUP (
gname => 'reptest');
END;
/
--將複製對象增長到複製組中
BEGIN
DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
gname => 'rep_test',
type => 'TABLE',
oname => 'employees',
sname => 'hr',
use_existing_object => TRUE,
copy_rows => FALSE);
END;
/
--生成複製支持
BEGIN
DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
sname => 'hr',
oname => 'employees',
type => 'TABLE',
min_communication => TRUE);
END;
/
--開始複製
BEGIN
DBMS_REPCAT.RESUME_MASTER_ACTIVITY (
gname => 'reptest');
END;
/
commit;
創建物化視圖
CONNECT hr/hr@prod ;
--創建物化視圖日誌表,FAST 刷新方式必需要求創建物化視圖日誌
CREATE MATERIALIZED VIEW LOG ON hr.employees;
--創建複製用戶到主站點代理刷新者的數據庫鏈
CONNECT hr/hr@emrep;
CREATE DATABASE LINK prod CONNECT TO repadmin IDENTIFIED BY repadmin;
--創建物化視圖組
CONNECT mvadmin/mvadmin@emrep ;
--物化視圖組必須和複製站點上的複製組名稱相同
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPGROUP (
gname => 'reptest',
master => 'prod',
propagation_mode => 'ASYNCHRONOUS');
END;
/
--建立刷新組
BEGIN
DBMS_REFRESH.MAKE (
name => 'mvadmin.rep_refresh',
list => '',
next_date => SYSDATE,
interval => 'SYSDATE + 1/24',
implicit_destroy => FALSE,
rollback_seg => '',
push_deferred_rpc => TRUE,
refresh_after_errors => FALSE);
END;
/
SQL> connect mviewadmin/mviewadmin@emrep ;
已鏈接。
SQL> select *from hr.employees@prod ;
SQL>
 
--建立物化視圖
SQL> CREATE MATERIALIZED VIEW hr.emp_up_view
REFRESH FAST WITH PRIMARY KEY FOR UPDATE
AS SELECT * FROM hr.employees@prod ;
相關文章
相關標籤/搜索