oracle stream 詳細配置

本文記錄了整個stream的配置過程,請根據環境的不一樣修改schema,以及相關路徑.sql

–1)設定初始化參數
–在線、備份數據庫分別執行以下的語句:
sqlplus '/ as sysdba'
alter system set aq_tm_processes=4 scope=both;
alter system set global_names=true scope=both;
alter system set job_queue_processes=10 scope=both;
alter system set parallel_max_servers=20 scope=both;
alter system set undo_retention=3600 scope=both;
alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;
alter system set streams_pool_size=500M scope=spfile;
alter system set utl_file_dir='*' scope=spfile;
alter system set open_links=6 scope=spfile;
alter database add supplemental log data;
–2)在線、備份庫設置爲歸檔模式
– 修改實際log_archive_dest_1路徑
sqlplus '/ as sysdba'
alter system set log_archive_dest_1='location=/oraarch/archdir' scope=spfile;
alter system set log_archive_start=TRUE scope=spfile;
--重啓數據庫
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
–3)建立STRMADMIN用戶
–  修改create_strmamin.sql中的表空間信息
–在線、備份
sqlplus '/ as sysdba'
-- 建立LOGMNRTS表空間
DROP TABLESPACE LOGMNRTS INCLUDING CONTENTS AND DATAFILES;
CREATE TABLESPACE LOGMNRTS DATAFILE
'/oradata/stream/logmnrts01.dbf' SIZE 500M AUTOEXTEND ON NEXT 8K MAXSIZE 2048M
LOGGING
ONLINE
PERMANENT
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
-- 建立STRMADMIN用戶
DROP USER STRMADMIN CASCADE;
CREATE USER STRMADMIN
IDENTIFIED BY STRMADMIN
DEFAULT TABLESPACE LOGMNRTS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
-- 4 Roles for STRMADMIN
GRANT RESOURCE TO STRMADMIN;
GRANT CONNECT TO STRMADMIN;
GRANT AQ_ADMINISTRATOR_ROLE TO STRMADMIN;
GRANT DBA TO STRMADMIN;
ALTER USER STRMADMIN DEFAULT ROLE ALL;
-- 16 System Privileges for STRMADMIN
BEGIN
SYS.DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE (
PRIVILEGE    => 'ENQUEUE_ANY',
GRANTEE      => 'STRMADMIN',
ADMIN_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.EXECUTE_ANY_RULE,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.ALTER_ANY_RULE,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE (
PRIVILEGE    => 'DEQUEUE_ANY',
GRANTEE      => 'STRMADMIN',
ADMIN_OPTION => TRUE);
END;
/
GRANT UNLIMITED TABLESPACE TO STRMADMIN;
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.CREATE_EVALUATION_CONTEXT_OBJ,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
GRANT SELECT ANY DICTIONARY TO STRMADMIN;
BEGIN
SYS.DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE (
PRIVILEGE    => 'MANAGE_ANY',
GRANTEE      => 'STRMADMIN',
ADMIN_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.EXECUTE_ANY_RULE_SET,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.CREATE_ANY_RULE_SET,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.CREATE_ANY_RULE,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.ALTER_ANY_RULE_SET,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.CREATE_RULE_SET_OBJ,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
GRANT RESTRICTED SESSION TO STRMADMIN;
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.CREATE_RULE_OBJ,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
BEGIN
SYS.DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
PRIVILEGE    => SYS.DBMS_RULE_ADM.EXECUTE_ANY_EVALUATION_CONTEXT,
GRANTEE      => 'STRMADMIN',
GRANT_OPTION => TRUE);
END;
/
-- 88 Object Privileges for STRMADMIN
GRANT SELECT ON SYS.AQ$INTERNET_USERS TO STRMADMIN;
GRANT SELECT ON SYS.AQ$_PROPAGATION_STATUS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_CONFLICT_COLUMNS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_DML_HANDLERS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_ENQUEUE TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_ERROR TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_EXECUTE TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_INSTANTIATED_GLOBAL TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_INSTANTIATED_OBJECTS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_INSTANTIATED_SCHEMAS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_KEY_COLUMNS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_PARAMETERS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_PROGRESS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_SPILL_TXN TO STRMADMIN;
GRANT SELECT ON SYS.DBA_APPLY_TABLE_COLUMNS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_AQ_AGENTS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_AQ_AGENT_PRIVS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_CAPTURE TO STRMADMIN;
GRANT SELECT ON SYS.DBA_CAPTURE_EXTRA_ATTRIBUTES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_CAPTURE_PARAMETERS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_CAPTURE_PREPARED_DATABASE TO STRMADMIN;
GRANT SELECT ON SYS.DBA_CAPTURE_PREPARED_SCHEMAS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_CAPTURE_PREPARED_TABLES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_EVALUATION_CONTEXTS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_EVALUATION_CONTEXT_TABLES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_EVALUATION_CONTEXT_VARS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_PROPAGATION TO STRMADMIN;
GRANT SELECT ON SYS.DBA_QUEUES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_QUEUE_PUBLISHERS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_QUEUE_SCHEDULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_QUEUE_SUBSCRIBERS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_QUEUE_TABLES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_REGISTERED_ARCHIVED_LOG TO STRMADMIN;
GRANT SELECT ON SYS.DBA_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_RULESETS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_RULE_SETS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_RULE_SET_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_ADD_COLUMN TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_ADMINISTRATOR TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_DELETE_COLUMN TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_GLOBAL_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_MESSAGE_CONSUMERS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_MESSAGE_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_NEWLY_SUPPORTED TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_RENAME_COLUMN TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_RENAME_SCHEMA TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_RENAME_TABLE TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_SCHEMA_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_TABLE_RULES TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_TRANSFORMATIONS TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_TRANSFORM_FUNCTION TO STRMADMIN;
GRANT SELECT ON SYS.DBA_STREAMS_UNSUPPORTED TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_APPLY_ADM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_AQ TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_AQADM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_AQELM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_AQIN TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_AQ_BQVIEW TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_CAPTURE_ADM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_FLASHBACK TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_PROPAGATION_ADM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_RULE_ADM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_STREAMS_ADM TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_STREAMS_MESSAGING TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_STREAMS_RPC TO STRMADMIN;
GRANT EXECUTE ON SYS.DBMS_TRANSFORM TO STRMADMIN;
GRANT SELECT ON SYS.GV_$AQ TO STRMADMIN;
GRANT SELECT ON SYS.GV_$BUFFERED_PUBLISHERS TO STRMADMIN;
GRANT SELECT ON SYS.GV_$BUFFERED_QUEUES TO STRMADMIN;
GRANT SELECT ON SYS.GV_$BUFFERED_SUBSCRIBERS TO STRMADMIN;
GRANT SELECT ON SYS.GV_$STREAMS_APPLY_COORDINATOR TO STRMADMIN;
GRANT SELECT ON SYS.GV_$STREAMS_APPLY_READER TO STRMADMIN;
GRANT SELECT ON SYS.GV_$STREAMS_APPLY_SERVER TO STRMADMIN;
GRANT SELECT ON SYS.GV_$STREAMS_CAPTURE TO STRMADMIN;
GRANT SELECT ON SYS.GV_$STREAMS_TRANSACTION TO STRMADMIN;
GRANT SELECT ON SYS.V_$AQ TO STRMADMIN;
GRANT SELECT ON SYS.V_$BUFFERED_PUBLISHERS TO STRMADMIN;
GRANT SELECT ON SYS.V_$BUFFERED_QUEUES TO STRMADMIN;
GRANT SELECT ON SYS.V_$BUFFERED_SUBSCRIBERS TO STRMADMIN;
GRANT SELECT ON SYS.V_$STREAMS_APPLY_COORDINATOR TO STRMADMIN;
GRANT SELECT ON SYS.V_$STREAMS_APPLY_READER TO STRMADMIN;
GRANT SELECT ON SYS.V_$STREAMS_APPLY_SERVER TO STRMADMIN;
GRANT SELECT ON SYS.V_$STREAMS_CAPTURE TO STRMADMIN;
GRANT SELECT ON SYS.V_$STREAMS_TRANSACTION TO STRMADMIN;
execute dbms_logmnr_d.set_tablespace('LOGMNRTS');
–4)建立DBLINK
–  在線庫和備份庫分別配置tnsnames.ora,分別要包含在線庫和備份庫
–  DBLink的名稱保持與GLOBAL_NAME一致  本例中在線庫GLOBAL_NAME:MC1
– 備份庫 GLOBAL_NAME:MC2
–在線
–DBLink 在線->備份
–查看global_name
select global_name from global_name;
sqlplus STRMADMIN/STRMADMIN
CREATE DATABASE LINK MC2 CONNECT TO STRMADMIN identified by STRMADMIN using 'MC2';
--備份
--DBLink 備份->在線
sqlplus STRMADMIN/STRMADMIN
CREATE DATABASE LINK  MC1  CONNECT TO STRMADMIN identified by STRMADMIN using ' MC1 ';
–5)建立stream隊列
–備份
sqlplus STRMADMIN/STRMADMIN
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE(
queue_table => 'STREAMS_QUEUE_TABLE',
queue_name => 'STREAMS_QUEUE',
queue_user => 'STRMADMIN');
END;
/
--在線
sqlplus STRMADMIN/STRMADMIN
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE (
queue_name => 'STREAMS_QUEUE',
queue_table =>'STREAMS_QUEUE_TABLE',
queue_user => 'STRMADMIN');
END;
/
–6)建立捕獲進程
– schema_name修改成實際須要同步的schema_name
– source_database修改成實際源數據庫庫
–在線
sqlplus STRMADMIN/STRMADMIN
BEGIN
DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'test',
streams_type => 'CAPTURE',
streams_name => 'STREAMS_CAPTURE',
queue_name => 'STREAMS_QUEUE',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
inclusion_rule => true,
source_database => null
);
END;
– schema_name修改成實際須要同步的schema_name
– destination_queue_name修改成實際目標庫
– source_database修改成實際源數據庫庫
BEGIN
DBMS_STREAMS_ADM.ADD_SCHEMA_PROPAGATION_RULES(
schema_name => 'test',
streams_name => 'STREAMS_PROPAGATE',
source_queue_name => 'STREAMS_QUEUE',
destination_queue_name => 'STREAMS_QUEUE@MC2',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'MC1',
inclusion_rule => true
);
END;
/
BEGIN
DBMS_AQADM.ALTER_PROPAGATION_SCHEDULE(
queue_name => 'STREAMS_QUEUE',
destination => 'MC2',
latency=> 0
);
END;
/
–7)建立應用進程
–備份
– schema_name修改成實際須要同步的schema_name
– source_database修改成實際源數據庫庫
sqlplus STRMADMIN/STRMADMIN
BEGIN
DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
schema_name => 'test',
streams_type => 'APPLY',
streams_name => 'STREAMS_APPLY',
queue_name => 'STRMADMIN.STREAMS_QUEUE',
include_dml => true,
include_ddl => true,
source_database => 'MC1');
END;
/
–8)stream參數設置
–在線
BEGIN
DBMS_CAPTURE_ADM.SET_PARAMETER(
capture_name  => 'STREAMS_CAPTURE',
parameter => 'disable_on_limit',
value  => 'N');
END;
/
BEGIN
DBMS_CAPTURE_ADM.SET_PARAMETER(
capture_name  => 'STREAMS_CAPTURE',
parameter => 'parallelism',
value  => '4');
END;
/
– 備份
– apply_user修改成實際用戶
sqlplus STRMADMIN/STRMADMIN
BEGIN
DBMS_APPLY_ADM.ALTER_APPLY(
apply_name => 'STREAMS_APPLY',
apply_user => 'test');
END;
/
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name  => 'STREAMS_APPLY',
parameter   => 'DISABLE_ON_ERROR',
value       => 'N' );
END;
/
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name  => 'STREAMS_APPLY',
parameter   => 'allow_duplicate_rows',
value       => 'Y' );
END;
/
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name  => 'STREAMS_APPLY',
parameter   => 'parallelism',
value       => '2' );
END;
/
–9)同步schema:test 的數據,具體操做省略
–10)stream啓動
–備份 啓動
sqlplus STRMADMIN/STRMADMIN
BEGIN
DBMS_APPLY_ADM.START_APPLY(apply_name  => 'STREAMS_APPLY');
END;
/
--在線 啓動
sqlplus STRMADMIN/STRMADMIN
exec dbms_capture_adm.START_CAPTURE (capture_name  => 'STREAMS_CAPTURE');
exec dbms_propagation_adm.START_PROPAGATION (PROPAGATION_NAME => 'STREAMS_PROPAGATE');
 
狀態查看:
1.登錄在線庫
SELECT CAPTURE_NAME, QUEUE_NAME, RULE_SET_NAME,NEGATIVE_RULE_SET_NAME,STATUS FROM DBA_CAPTURE;
若是STATUS狀態是ENABLED,表示Capture進程運行正常;
若是STATUS狀態是DISABLED,表示Capture進程處於中止狀態,只需從新啓動便可;
若是STATUS狀態是ABORTED,表示Capture進程非正常中止,查詢相應的ERROR_NUMBER、ERROR_MESSAGE列能夠獲得詳細的信息;同時,Oracle會在跟蹤文件中記錄該信息。
SELECT CAPTURE_NAME, QUEUE_NAME, STATUS, CAPTURED_SCN, APPLIED_SCN FROM DBA_CAPTURE;
若是APPLIED_SCN小於CAPTURED_SCN,則表示在主數據庫一端,要麼LCR沒有被dequeue,要麼Propagation進程還沒有傳播到從數據庫一端。
2.登錄備份庫
 SELECT apply_name, apply_captured, status FROM dba_apply;
若是STATUS狀態是ENABLED,表示Apply進程運行正常;
若是STATUS狀態是DISABLED,表示Apply進程處於中止狀態,只需從新啓動便可;
若是STATUS狀態是ABORTED,表示Apply進程非正常中止,查詢相應的ERROR_NUMBER、ERROR_MESSAGE列能夠獲得詳細的信息;同時,能夠查詢DBA_APPLY_ERROR視圖,瞭解詳細的Apply錯誤信息。
相關文章
相關標籤/搜索