通過Oracle Stream實現資料庫之間的同步

2021-06-05 17:29:08 字數 4903 閱讀 8109

oracle stream功能是為提高資料庫的高可用性而設計的,在oracle 9i及之前的版本這個功能被稱為advance replication。oracle stream利用高階佇列技術,通過解析歸檔日誌,將歸檔日誌解析成ddl及dml語句,從而實現資料庫之間的同步。這種技術可以將整個資料庫、資料庫中的物件複製到另一資料庫中,通過使用stream的技術,對歸檔日誌的挖掘,可以在對主系統沒有任何壓力的情況下,實現對資料庫物件級甚至整個資料庫的同步。

一、步驟

-以下均為源和目標資料庫的sys使用者執行的操作:

1、將源和目標資料庫設定為歸檔模式

2、啟動源和目標全域性資料庫名,並設定全域性資料庫名

3、建立源和目標的stream管理員表空間、使用者、並授權

4、建立logmnr表空間,並將logminer的資料字典轉移到新建的表空間

5、建立測試使用者

以下為stream管理員在源資料庫上的操作:

6、stream管理員建立資料庫鏈結

7、建立master流隊伍

8、建立捕獲程序

10、建立傳播程序

11、修改propagation休眠時間為0,表示實時傳播lcr

以下為stream管理員在目標資料庫上的操作:

9、例項化複製資料庫應當在目標庫上完成

12、建立backup流佇列

13、建立應用程序

14、啟動應用程序

15、啟動捕獲程序。

二、詳細步驟

以下以system as sysdba身份登入

檢視是否歸檔模式的sql語句

select log_mode from v$database;

初始化資料庫引數

alter system set global_names=true scope=both;

alter system set undo_retention=3600 scope=both;

alter system set job_queue_processes=4 scope=both;

alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss' scope=spfile;

alter system set open_links=4 scope=spfile;

alter system set aq_tm_processes =4;

建立流管理使用者的表空間,資料檔案,使用者授權

create user stream_admin identified by stream_admin default tablespace stream_admin;

grant dba to stream_admin;

grant create session to stream_admin;

grant aq_administrator_role to stream_admin;

grant unlimited tablespace to stream_admin;*/

流管理使用者的授權

begin

dbms_streams_auth.grant_admin_privilege(

grantee=>'stream_admin',

grant_privileges=>true);

end;

建立流使用者的表空間,資料檔案,使用者授權

create user stream identified by stream default tablespace stream;

grant resource to stream;

grant create session to stream;

grant unlimited tablespace to stream;*/

以下是以流管理使用者身份登入源資料庫

建立流佇列

begin

dbms_streams_adm.set_up_queue(

queue_table => 'stream_admin.stream_source_queue_table',

queue_name => 'stream_admin.stream_source_queue');

end;

建立dblink

create database link target.net connect to stream_admin identified by stream_admin using 'target';

檢視dblink

select sysdate from [email protected];

建立捕獲程序

begin

dbms_streams_adm.add_schema_rules(

schema_name => 'stream',

streams_type => 'capture',

streams_name => 'stream_source_capture',

queue_name => 'stream_admin.stream_source_queue',

include_dml => true,

include_ddl => true,

include_tagged_lcr => false,

source_database => 'source.net',

inclusion_rule => true);

end;

建立傳播作業

begin

dbms_streams_adm.add_schema_propagation_rules(

schema_name => 'stream',

streams_name => 'stream_source_propagation',

source_queue_name => 'stream_admin.stream_source_queue',

destination_queue_name => '[email protected]', ----目標資料上的佇列名稱

include_dml => true,

include_ddl => true,

include_tagged_lcr => false,

source_database => 'source.net',

inclusion_rule => true);

end;

例項化scn

create or replace procedure init_scn

isv_scn number(30);

begin

v_scn:=dbms_flashback.get_system_change_number();

source_schema_name =>'stream',

source_database_name =>'source',

instantiation_scn =>v_scn,

recursive=>true );

end init_scn;

啟動 capture捕獲程序

begin

dbms_capture_adm.start_capture(

capture_name => 'stream_source_capture');

end;

以下是以流管理使用者身份登入目標資料庫

建立dblink

create database link source.net connect to stream_admin identified by stream_admin using 'source';

檢視dblink

select sysdate from [email protected];

建立流佇列

begin

dbms_streams_adm.set_up_queue(

queue_table => 'streamadmin.stream_target_queue_table',

queue_name => 'streamadmin.stream_target_queue');

end;

建立應用作業

begin

dbms_streams_adm.add_schema_rules(

schema_name => 'stream',

queue_name => 'stream_admin.stream_target_queue',

include_dml => true,

include_ddl => true,

include_tagged_lcr => false,

source_database => 'target.net',

inclusion_rule => true);

end;

begin

end;

三、常用sql

查詢使用者

select * from dba_users;

select * from user$ where name='streamadmin';

刪除使用者

drop user stream_admin;

select username from dba_users;

查詢表空間

select * from dba_tablespaces;

刪除表空間

drop tablespace stream_admin;

查詢佇列

select * from dba_queues;

查詢屬於某個使用者下的佇列

select * from dba_queues where owner='streamadmin';

查詢應用程序

查詢select * from link$ where name='target.net';

512m;

Pytorch學習筆記之通過numpy實現線性擬合

通過使用numpy庫編寫簡單的gradient descent資料位於附件之中 import torch from torch import autograd import numpy as np import matplotlib.pyplot as plt torch關於求導的簡單運用 x to...

通過leetcode學習位運算及其Go實現

461.hamming distance 即求兩個正整數的二進位制對應位數不同的個數 從問題描述來看,最直觀的解決方法就是十進位制數先轉成二進位制,再比對相同位數是否相同,不同則計數器累加,最終計數器的值即是hamming distance。優化方案 先 運算,對運算結果的位數進行遍歷,1則計數器累...

MFC通過ODBC連線MySQL資料庫例項

乙個小的mfc通過odbc連線mysql資料庫登陸例項 檔案 n459.com file 25127180 479633004 訪問密碼 551685 以下內容無關 分割線 其實我很早就想寫寫分布式資料庫相關的文章,既是我現在正在學習的,也是我很感興趣的內容。但是談到分布式資料庫,會涉及很多相關的技...