oracle 複製基於表複製配置過程;數據庫
規劃:oracle
檢查oarcle數據庫是否支持高級複製功能,trueide
>Select value from v$OPTION where parameter='advanced replicaiont'函數
2,是否支持global_names工具
(當GLOBAL_NAMES參數設置爲TRUE時,使用DATABASE LINK時,DATABASE LINK的名稱必須與被鏈接庫的GLOBAL_NAME一致)測試
>show parameter global_names ;結果爲truespa
查看global_name配置:code
>select * from global_name;server
3,查看job_queue_processes; 在0-1000之間htm
>show parameter job_queue_processes;
4,查看open_links
>show parameter open_links; default:4 不可更改
5,查看全局數據庫名稱:
>select * from global_name;
6,設置全局數據庫名稱(安裝過程當中因爲字符串長度等緣由,實際global_name配置不正確,安裝完成更改便可。不然dblink鏈接不上):
>alter database rename global_name to masterone.test.com;
>alter database rename global_name to mastertwo.test.com;
1,建立數據庫, 全局數據庫名稱分別爲:masterone.test.com/mastertwo.test.com Serivce name 分別爲:masterone.test.com/mastertwo.test.com 2,在兩個數據庫中tnsnames.ora配置客戶訪問:配置內容以下: MASTERTWO = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = mastertwo.test.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mastertwo.test.com) ) ) MASTERONE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = masterone.test.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = masterone.test.com) ) ) 3,打開SQL Plus測試連接(保證數據庫可聯通) >connect system@masterone; >connect system@mastertwo; 4,建立replication admin ,使用system鏈接masterone.test.com數據庫; 5,建立repadmin 執行命令 Create user repadmin identified by repadmin; 6,賦予repadmin用戶能夠建立和管理複製環境的權限 Exec dbms_repcat_admin.grant_admin_any_schema(username=>'repadmin'); Grant comment any table to repadmin; Grant lock any table to repadmin; 若是使用OEM管理工具,還需執行以下命令: GRANT SELECT ANY DICTIONARY TO repadmin; 7,註冊repadmin爲傳播函數 Exec dbms_defer_sys.register_propagator(username=>'repadmin'); 8,註冊repadmin爲接受函數 BEGIN DBMS_REPCAT_ADMIN.REGISTER_USER_REPGROUP ( username => 'repadmin', privilege_type => 'receiver', list_of_gnames => NULL); END; 9,爲了在檢查時保持延遲事務隊列的大小, 您應該清除已成功完成的延遲事務。SCHEDULE_PURGE 過程爲您自動清除過程。使用repadmin登錄數據庫 Connect repadmin; BEGIN DBMS_DEFER_SYS.SCHEDULE_PURGE ( next_date => SYSDATE, interval => 'SYSDATE + 1/24', delay_seconds => 0); END; 10,在mastertwo.mor.cr上執行相同操做4-9; 11,使用system在masterone.test.com上建立共有dblink Connect system@masterone Create public datebase link mastertwo.test.com using 'mastertwo'; Connect repadmin@masterone Create database link mastertwo.test.com connect to repadmin identified by repadmin; 使用system在mastertwo.test.com上建立共有dblink Connect system@mastertwo; Create public database link masterone.test.com using 'masterone'; Connect repadmin@mastertwo Create database link masterone.mor.cr connect to repadmin identified by repadmin; 12,使用repadmin登錄masterone.test.com/mastertwo.test.com Connect repadmin@masterone BEGIN DBMS_DEFER_SYS.SCHEDULE_PUSH ( destination => 'mastertwo.test.com', interval => 'SYSDATE + (1/144)', next_date => SYSDATE, parallelism => 1, execution_seconds => 1500, delay_seconds => 1200); /*延遲時間能夠設置小一點*/ END; Connect repadmin@mastertwo BEGIN DBMS_DEFER_SYS.SCHEDULE_PUSH ( destination => 'masterone.test.com', interval => 'SYSDATE + (1/144)', next_date => SYSDATE, parallelism => 1, execution_seconds => 1500, delay_seconds => 1200); END; 13,建立master group 在建立同步組以前應該確保複製環境的中的每一個數據庫中有相同的schema和表結構。例如在測試環境中定義的schema爲hr,表結構爲test 只在master site上執行此操做:masterone.test.com做爲master site Connect repadmin@masterone Exec dbms_repcat.create_master_repgroup('hrgroup') 14,向master group中添加object BEGIN DBMS_REPCAT.CREATE_MASTER_REPOBJECT ( gname => 'hrgroup', type => 'TABLE', oname => 'test', sname => 'hr', use_existing_object => TRUE, copy_rows => FALSE); END; 15,添加額外的master site BEGIN DBMS_REPCAT.ADD_MASTER_DATABASE ( gname => 'hrgroup', master => 'mastertwo.test.com', use_existing_objects => TRUE, copy_rows => FALSE, propagation_mode => 'ASYNCHRONOUS'); END; 使用以下命令檢查,若是出現兩個數據庫的鏈接則操做成功 SELECT DBLINK FROM DBA_REPSITES WHERE GNAME = 'HRGROUP'; mastertwo.test.com masterone.test.com 16,添加複製支持 BEGIN DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT ( sname => 'hr', oname => 'test', type => 'TABLE', min_communication => TRUE); END; 完成檢查經過命令檢查,返回0可繼續執行 SELECT COUNT(*) FROM DBA_REPCATLOG WHERE GNAME = 'HRGROUP'; 17,啓用複製 BEGIN DBMS_REPCAT.RESUME_MASTER_ACTIVITY ( gname => 'hrgroup'); END; 18,測試 在masterone.test.com上hr.test表中分別經過進行增刪改操做 Insert into hr.test values (1,'testuser1'); Commit;(在SQL Plus上操道別忘提交) 因爲複製延遲爲1200,毫秒因此不會很快同步到mastertwo.test.com上
參考地址:https://docs.oracle.com/cd/B28359_01/server.111/b28327/rarmastergroup.htm#i1004613