Oracle simple stream
一.Single stream #9R2和10g均可設定
1.主從庫必須起動歸檔
主庫可以基於Database級別或Table級別,啟用追加日誌(Supplemental Log)。在建立根據Schema粒度進行復制的Oracle Stream 環境中,如果確認Schema 下所有Table 都有合理的主鍵(Primary Key),則不再需要啟用追加日誌。
#啟用Database 追加日誌
alter database add supplemental log data;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX, FOREIGN KEY) COLUMNS;
#啟用Table追加日誌
alter table add supplement log group log_group_name(table_column_name) always;
2.主從建streams admin 表空間
CREATE TABLESPACE streams_tbs DATAFILE '/u01/app/oracle/oradata/sid/streams_tbs.dbf' size 50M reuse autoextend on maxsize unlimited;
3.主從建streams user
CREATE USER strmadmin IDENTIFIED BY strmadmin DEFAULT TABLESPACE streams_tbs temporary tablespace temp QUOTA UNLIMITED ON streams_tbs;
grant connect,resource,dba,aq_administrator_role to strmadmin;
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'strmadmin',
grant_privileges => true);
END;
4.主從建立DB link #propagate messages from a source queue at a database to a destination queue
connect
create public database link qhrac connect to strmadmin identified by strmadmin using 'qhrac';
connect
create public database link qhadb connect to strmadmin identified by strmadmin using 'qhrac';
5.主庫引數修改,並在歸檔下
alter system set aq_tm_processes=2 scope=both; //不要設定成0或者10, 這樣做可能禁用佇列監測處理和影響流池記憶體利用率
alter system set global_names=true scope=both;
alter system set job_queue_processes=10 scope=both; //建議的最低值為4,定義傳播程式數
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=200M scope=spfile; //沒有捕獲程式無須配置此處
alter system set open_links=4 scope=spfile; //資料庫連線數.DB_LINK
6.主庫create queue
connect strmadmin/strmadmin
begin
dbms_streams_adm.set_up_queue(
queue_table => 'qhadb_queue_table',
queue_name => 'qhadb_queue');
end;
7.從庫create queue
connect strmadmin/strmadmin
begin
dbms_streams_adm.set_up_queue(
queue_table => 'qhrac_queue_table',
queue_name => 'qhrac_queue');
end;
8.主庫建立捕獲程式
connect strmadmin/strmadmin
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'hs_his',
streams_type => 'capture',
streams_name => 'capture_qhadb',
queue_name => 'strmadmin.qhadb_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => true,
source_database => null,
inclusion_rule => true);
end;
9.例項化複製資料庫
主資料庫exp -> 從資料庫
impdp system/oracle network_link=qhadb schemas=hs_his
connect strmadmin/strmadmin
DECLARE
iscn NUMBER;
BEGIN
iscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
(
source_schema_name => 'hs_his',
source_database_name => 'qhadb',
instantiation_scn => iscn,
recursive => true);
END;
10.主庫建立傳播程式##queue_to_queue =ture automatic failover when the destination queue is a buffered queue in a Real Application Clusters (RAC) database
connect strmadmin/strmadmin
begin
dbms_streams_adm.add_schema_propagation_rules(
schema_name => 'hs_his',
streams_name => 'qhadb_to_qhrac',
source_queue_name => 'strmadmin.qhadb_queue',
destination_queue_name => ,
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'qhadb',
inclusion_rule => true,
queue_to_queue => true);
end;
修改propagation休眠時間為0,表示實時傳播LCR
begin
dbms_aqadm.alter_propagation_schedule(
queue_name => 'qhadb_queue',
destination => 'qhrac',
latency => 0);
end;
11.從庫建立應用程式
connect strmadmin/strmadmin
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'hs_his',
streams_type => 'apply',
streams_name => 'apply_qhrac',
queue_name => 'strmadmin.qhrac_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => true,
source_database => 'qhadb',
inclusion_rule => true);
end;
12.從庫啟動Apply程式
CONNECT strmadmin/strmadmin
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name => 'apply_qhrac',
parameter => 'disable_on_error',
value => 'n');
begin
dbms_apply_adm.start_apply(
apply_name => 'apply_qhrac');
end;
停止
connect strmadmin/strmadmin
begin
dbms_apply_adm.stop_apply(
apply_name => 'apply_qhrac');
end;
13.主庫啟動Capture程式
connect strmadmin/strmadmin
begin
dbms_capture_adm.start_capture(
capture_name => 'capture_qhadb');
end;
停止
connect strmadmin/strmadmin
begin
dbms_capture_adm.stop_capture(
capture_name => 'capture_qhadb');
end;
14.清除Stream配置資訊(先要停),主從庫,10.2.0.3以前會報錯Bug 5640593
connect strmadmin/strmadmin
exec DBMS_STREAMS_ADM.remove_streams_configuration();
15.管理
檢視道捕捉(Capture)程式
SELECT CAPTURE_NAME,QUEUE_NAME,RULE_SET_NAME,NEGATIVE_RULE_SET_NAME,START_SCN,STATUS,CAPTURE_TYPE FROM DBA_CAPTURE;
STATUS:ENABLED,表示Capture程式執行正常;
DISABLED,表示Capture程式處於停止狀態,只需重新啟動即可;
ABORTED,表示Capture 程式非正常停止,查詢相應的ERROR_NUMBER、ERROR_MESSAGE 列可以得到詳細的資訊;同時,Oracle會在跟蹤檔案中記錄該資訊。
select sid,serial#,capture_name,startup_time,state,state_changed_time from v$streams_capture
state: INITIALIZING-開始
WAITING FOR DICTIONARY REDO ---等待包含關係first scn的字典的redo log 檔案被加進捕獲程式會話。直到所有包含字典的redo log檔案被加,捕獲程式才可以開始掃描redo log檔案。
CAPTURING CHANGES ---掃描redo log。
CREATING LCR ---把改變格式化成LCR。
ENQUEUING MESSAGE ---把滿足規則的LCR塞進捕獲佇列。
PAUSED FOR FLOW CONTROL ---不能夠塞LCR進佇列。可能由於傳播或應用程式消化訊息慢過捕獲程式建立訊息。當傳播包或應用程式遠遠落後或不可用時,它可以提醒,減少遺漏捕獲的資訊。
select * from ALL_CAPTURE_PREPARED_SCHEMAS;
查Captured LCR是否有傳播GAP?
SELECT CAPTURE_NAME, QUEUE_NAME, STATUS, CAPTURED_SCN,APPLIED_SCN FROM DBA_CAPTURE;
如果APPLIED_SCN 小於CAPTURED_SCN,則表示在主資料庫一端,要麼LCR 沒有被dequeue,要麼Propagation程式尚未傳播到從資料庫一端。
查Appy程式
SELECT apply_name, apply_captured, status,error_message FROM dba_apply;
STATUS:ENABLED,表示Apply程式執行正常;
DISABLED,表示Apply程式處於停止狀態,只需重新啟動即可;
ABORTED,表示Apply 程式非正常停止,查詢相應的ERROR_NUMBER、ERROR_MESSAGE 列可以得到詳細的資訊;同時,可以查詢DBA_APPLY_ERROR檢視,瞭解詳細的Apply錯誤資訊。
select apply_name,queue_name,message_number,error_number,error_message,message_count,error_creation_time from DBA_APPLY_ERROR;
v$streams_apply_reader
v$streams_apply_coordinator
v$streams_apply_server
16.從庫和主庫之間時間間隔跟效能及其它情況有關,包括capture mining logfile的速度,propagation的間隔(預設3秒)及傳輸時間,apply log的速度
二.example
在Oracle Stream Replication提供的庫中,有一個SubSet的概念,可以把一個Table的資料做一個Horizontal的Partition,也就是說可以水平分割Table中的資料,
來實現資料的同步。但是在某些應用場合,存在這樣的需求,就是一個Table中的一些欄位Change的頻率相當頻繁,而這些Column是特定於本地的AS的,
A Site的這些Column的值對於B Site的AS來說,無關緊要。因為,在應用上通常,B Site的AS會重新設定這些Column的值。
如果Stream replication對Replication不加以區分的話,那這些changes很頻繁的Column會給整個系統帶來很大的效能影響,
特別是在3個Site的相互Replication上。
複製或同步部分欄位,而不是整個表欄位, 實現的方法是採用Rule-base Transformation,而且是針對Capture Process,因為如果不從Source DB源頭做的話,透過大量的Propagation和Apply,對系統的效能影響和不做是沒太大的區別的。
以2個Site的Replication為例:db1 --> db2
1.首先,建立相應的Capture、Apply和Propagation,以schema的級別來Setup,而且建立起來的Rule都是屬於Positive的,不是Negative.
rem ;set up the apply queues
rem ;*************************************************************************
begin
dbms_streams_adm.set_up_queue(
queue_table => 'apply_db2tab',
queue_name => 'apply_db2',
queue_user => 'strmadmin');
end;
/
rem ;set up the capture queue
rem ;*************************************************************************
begin
dbms_streams_adm.set_up_queue(
queue_table => 'capture_db1tab',
queue_name => 'capture_db1',
queue_user => 'strmadmin');
end;
/
rem ;set up the apply process
rem ;*************************************************************************
begin
dbms_streams_adm.add_schema_rules (
schema_name => 'bartholo',
streams_type => 'apply',
streams_name => 'apply_src_db2',
queue_name => 'apply_db2',
include_dml => true,
include_ddl => true,
source_database => 'db2.world');
end;
/
rem ;set up the capture process
rem ;*************************************************************************
begin
dbms_streams_adm.add_schema_rules (
schema_name => 'bartholo',
streams_type => 'capture',
streams_name => 'capture_db1strm',
queue_name => 'capture_db1',
include_dml => true,
include_ddl => true,
inclusion_rule => true);
end;
/
rem ;set up the propagation process
rem ;*************************************************************************
begin
dbms_streams_adm.add_schema_propagation_rules (
schema_name => 'bartholo',
streams_name => 'prop_db1_to_db2',
source_queue_name => 'capture_db1',
destination_queue_name => ,
include_dml => true,
include_ddl => true,
source_database => 'db1.world');
end;
/
2.這裡我的Stream User是strmadmin,已經給以了DBA的許可權。這部要做的是實現一個Transform. Function.
這裡假設我們的Table是這樣定義的:tab1(col1, col2, col3)其中col3的Update操作不做Replication.達到的目標是:不管Source Site對Col3做任何的Update修改,在目的站點都是看不見,保持不變。
CREATE OR REPLACE PACKAGE strmpkg as
function transform_capture(in_any IN SYS.AnyData) RETURN SYS.AnyData;
END strmpkg;
/
CREATE OR REPLACE PACKAGE BODY strmpkg as
FUNCTION transform_capture(in_any IN SYS.AnyData)
RETURN SYS.AnyData
IS
lcr SYS.LCR$_ROW_RECORD;
rc NUMBER;
ob_owner VARCHAR2(30);
ob_name VARCHAR2(30);
cmd VARCHAR2(10);
newvalue_anydata SYS.AnyData;
oldvalue_anydata SYS.Anydata;
BEGIN
IF in_any.GETTYPENAME='SYS.LCR$_ROW_RECORD' THEN
-- Put the row LCR into lcr
rc := in_any.GETOBJECT(lcr);
-- Get the object owner and name
ob_owner := lcr.GET_OBJECT_OWNER();
ob_name := lcr.GET_OBJECT_NAME();
cmd := lcr.GET_COMMAND_TYPE();
--只對bartholo這個schema 和 Update的操作進行轉換,其它的放行
IF ob_owner = 'bartholo' AND cmd = 'UPDATE' THEN
IF ob_name = 'tab1' THEN
-- Remove the specified column in the LCR
newvalue_anydata := lcr.GET_VALUE('new','col3');
oldvalue_anydata := lcr.GET_VALUE('old','col3');
IF ( (newvalue_anydata IS NOT NULL) OR (oldvalue_anydata IS NOT NULL) )
THEN
--just only the column existed, u can delte the column
lcr.DELETE_COLUMN(column_name => 'col3');
END IF;
END IF;
END IF;
RETURN SYS.ANYDATA.CONVERTOBJECT(lcr);
END IF;
RETURN in_any;
END transform_capture;
END strmpkg;
/
3.把這個Transform. Function和Capture的DML Rule關聯起來。
DECLARE
capture_dml_rule VARCHAR2(30);
BEGIN
SELECT rule_name INTO capture_dml_rule FROM sys.streams$_rules
WHERE streams_name='CAPTURE_DB1STRM' and rule_type = 1 AND ROWNUM = 1
ORDER BY rule_name DESC;
DBMS_STREAMS_ADM.set_rule_transform_function(
rule_name => capture_dml_rule,
transform_function => 'strmpkg.transform_capture');
END;
/
4.把Schema及其包含的物件在2站點上相互做個Instantiation.
DECLARE
iscn NUMBER; -- Variable to hold instantiation SCN value
BEGIN
iscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
DBMS_OUTPUT.PUT_LINE('The SCN for db2 and db3: ' || iscn);
(
source_schema_name => 'bartholo',
source_database_name => 'db1.world',
instantiation_scn => iscn);
END;
/
5.啟動db2站點上的Apply, DB1上的Propagation和Capture。
三.一對多複製
一對多與一對一不同的就是,在源資料庫傳播的時候要向多個目標資料庫傳播,每個目標資料庫都要配置相應的應用程式
db1-->db2;db1-->db3
1.引數修改(db1,db2,db3)
alter system set aq_tm_processes=4 scope=spfile;
alter system set global_names=true scope=spfile;
alter system set job_queue_processes=8 scope=spfile;
alter system set log_parallelism=1 scope=spfile;
alter system set global_names=true scope=spfile;
2.建立流管理員,並對其進行授權(db1,db2,db3)
CREATE USER strmadmin IDENTIFIED BY strmadmin DEFAULT TABLESPACE users QUOTA UNLIMITED ON users;
GRANT DBA, CONNECT, RESOURCE, SELECT_CATALOG_ROLE TO strmadmin;
GRANT EXECUTE ON DBMS_AQADM TO strmadmin;
GRANT EXECUTE ON DBMS_CAPTURE_ADM TO strmadmin;
GRANT EXECUTE ON DBMS_PROPAGATION_ADM TO strmadmin;
GRANT EXECUTE ON DBMS_STREAMS_ADM TO strmadmin;
GRANT EXECUTE ON DBMS_APPLY_ADM TO strmadmin;
GRANT EXECUTE ON DBMS_FLASHBACK TO strmadmin;
GRANT ALL ON scott.dept TO strmadmin;
BEGIN
DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
privilege => DBMS_RULE_ADM.CREATE_RULE_SET_OBJ,
grantee => 'strmadmin',
grant_option => FALSE);
END;
/
BEGIN
DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE(
privilege => DBMS_RULE_ADM.CREATE_RULE_OBJ,
grantee => 'strmadmin',
grant_option => FALSE);
END;
/
3.建db link
db1:
create public database link db2 connect to strmadmin identified by strmadmin using 'db2';
create public database link db3 connect to strmadmin identified by strmadmin using 'db3';
db2,db3:
create public database link db1 connect to strmadmin identified by strmadmin using 'db1';
4.建立LogMinor 表空間,並新增SUPPLEMENTAL 日誌 (db1)
conn /as sysdba
CREATE TABLESPACE logmnr_ts DATAFILE 'D:\oracle\product\10.2.0\oradata\orcl\logmnr01.dbf' SIZE 25 M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnr_ts');
#啟用Database 追加日誌
alter database add supplemental log data;
#啟用Table追加日誌
alter table *** add supplement log group log_group_name(table_column_name) always;
5.配置傳播程式(db1)
conn
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_PROPAGATION_RULES(
table_name => 'scott.dept',
streams_name => 'db1_to_db2',
source_queue_name => 'strmadmin.streams_queue',
destination_queue_name => ,
include_dml => true,
include_ddl => true,
source_database => 'db1');
END;
/
備註:引數destination_queue_name中的db2是建立的指向db2資料庫的db link,source_database的值必須是目標資料庫指向源資料庫的db link;
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_PROPAGATION_RULES(
table_name => 'scott.dept',
streams_name => 'db1_to_db3',
source_queue_name => 'strmadmin.streams_queue',
destination_queue_name => ,
include_dml => true,
include_ddl => true,
source_database => 'db1');
END;
/
檢查傳播程式作業
SELECT job,TO_CHAR(last_date, 'DD-Mon-YYYY HH24:MI:SS') last_date,TO_CHAR(next_date, 'DD-Mon-YYYY HH24:MI:SS') next_date,what FROM dba_jobs;
6.配置捕捉程式(db1)
CONNECT
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_RULES(
table_name => 'scott.dept',
streams_type => 'capture',
streams_name => 'capture_simp',
queue_name => 'strmadmin.streams_queue',
include_dml => true,
include_ddl => true);
END;
/
7.配置初始 SCN
在應用程式工作前必須在目的表中配置源表的 SCN。如果目的表已經存在,可用 exp/imp 後設資料完成。
exp FILE=dept_instant.dmp TABLES=dept OBJECT_CONSISTENT=y ROWS=n
imp FILE=dept_instant.dmp IGNORE=y COMMIT=y LOG=import.log STREAMS_INSTANTIATION=y
imp FILE=dept_instant.dmp IGNORE=y COMMIT=y LOG=import.log STREAMS_INSTANTIATION=y
因為在遷移後設資料時 SUPPLEMENTAL 日誌也被遷移。因為捕捉程式還沒有啟動,所以可以刪除這些日誌:
CONN AS SYSDBA
ALTER TABLE scott.dept DROP SUPPLEMENTAL LOG GROUP log_group_dept_pk;
CONN AS SYSDBA
ALTER TABLE scott.dept DROP SUPPLEMENTAL LOG GROUP log_group_dept_pk;
用 DBMS_APPLY_ADM 包設定 SCN
DECLARE
v_scn NUMBER;
BEGIN
v_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
(
source_object_name => 'scott.dept',
source_database_name => 'db1',
instantiation_scn => v_scn);
END;
/
DECLARE
v_scn NUMBER;
BEGIN
v_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
(
source_object_name => 'scott.dept',
source_database_name => 'db1',
instantiation_scn => v_scn);
END;
/
8.配置應用程式(db2,db3)
db2:
CONNECT
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_RULES(
table_name => 'scott.dept',
streams_type => 'apply',
streams_name => 'apply_simp',
queue_name => 'strmadmin.streams_queue',
include_dml => true,
include_ddl => true,
source_database => 'db1');
END;
/
db3:
CONNECT
BEGIN
DBMS_STREAMS_ADM.ADD_TABLE_RULES(
table_name => 'scott.dept',
streams_type => 'apply',
streams_name => 'apply_simp',
queue_name => 'strmadmin.streams_queue',
include_dml => true,
include_ddl => true,
source_database => 'db1');
END;
9.啟動應用程式(db2,db3)
CONNECT
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name => 'apply_simp',
parameter => 'disable_on_error',
value => 'n');
DBMS_APPLY_ADM.START_APPLY(
apply_name => 'apply_simp');
END;
/
BEGIN
DBMS_APPLY_ADM.SET_PARAMETER(
apply_name => 'apply_simp',
parameter => 'disable_on_error',
value => 'n');
DBMS_APPLY_ADM.START_APPLY(
apply_name => 'apply_simp');
END;
/
10.啟動捕捉程式(db1)
CONNECT
BEGIN
DBMS_CAPTURE_ADM.START_CAPTURE(
capture_name => 'capture_simp');
END;
/
四.dbms_streams_adm的maintain_global過程如何配置stream全庫複製方法,適用於10gR2及以後版本
主從庫SID和目錄結構要求一致
1 在stream進行配置前,需要做些準備工作
源庫與目標庫初始化引數的設定
alter system set aq_tm_processes=4 scope=spfile;
alter system set job_queue_processes=5 scope=spfile;
alter system set global_names=true scope=spfile;
alter system set streams_pool_size=51m scope=spfile;
說明streams_pool_size在生產環境中最好>200m
b 源庫與目標庫tnsnames.ora配置
確保正確,可用tnsping通
c 源庫與目標庫複製管理員的建立
create user strmadmin identified by strmadmin default tablespace &tbs_name quota unlimited on &tbs_name;
grant connect, resource, dba to strmadmin;
d 源庫與目標庫建立互連的資料鏈
connect ;
create public database link db2.com connect to strmadmin identified by strmadmin using 'db2';
connect ;
create public database link db1.com connect to strmadmin identified by strmadmin using 'db1';
(說明:必須確保雙方的資料庫鏈是可以連通,用pre_instantiation_setup/post_instantiation_setup過程時db link必須用db_name.domain的格式)
e 源庫與目標庫必須處於歸檔模式
f 源庫與目標庫必須建立directory
create directory dir_db1 as '/u01/bak';
create directory dir_db2 as '/u01/bak';
2 在源庫執行MAINTAIN_GLOBAL過程(整庫級)
connect ;
begin
dbms_streams_adm.maintain_global(
source_directory_object => 'dir_db1',
destination_directory_object => 'dir_db2',
source_database => 'db1.com',
destination_database => 'db2.com',
perform_actions => true,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_FULL_NETWORK);
end;
說明:在執行maintain_global時,源庫與目標庫必須建立directory,然後在源庫執行, 目標庫幾乎什麼都不用做,stream環境已經配置好
其中,instantiation指定初始化的方式
DBMS_STREAMS_ADM.INSTANTIATION_FULL:expdp全庫匯出然後impdp全庫匯入
DBMS_STREAMS_ADM.INSTANTIATION_FULL_NETWORK:使用data pump直接透過網路匯入的特性初始化
DBMS_STREAMS_ADM.INSTANTIATION_NONE:不執行初始化。這個選現只有在perform_actions=false的情況下有效,也就是指定先生成指令碼,手工初始化,然後在執行配置指令碼。
begin
DBMS_STREAMS_ADM.MAINTAIN_GLOBAL(
source_directory_object => 'dir_db1',
destination_directory_object => 'dir_db2',
source_database => 'db1.com',
destination_database => 'db2.com',
perform_actions => false,
script_directory_object =>'DIR_db1',
script_name => 'global_script.sql',
dump_file_name => 'streams_rep.dmp',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_NONE);
end;
在源庫執行MAINTAIN_schemas過程(schema級,注意:從庫schemas最好不存在)
connect ;
begin
dbms_streams_adm.maintain_schemas(
schema_names => 'hs_his,hs_users',
source_directory_object => null,
destination_directory_object => null,
source_database => 'db1.com',
destination_database => 'db2.com',
perform_actions => true,
bi_directional => false,
include_ddl => true,
instantiation => dbms_streams_adm.instantiation_schema_network);
end;
在源庫執行MAINTAIN_TTS過程(table級)
connect ;
declare
v_tables dbms_utility.uncl_array;
begin
v_tables(1) := 'scott.scott';
v_tables(2) := 'scott.tiger';
dbms_streams_adm.maintain_tables(
table_names => v_tables,
source_directory_object => null,
destination_directory_object => null,
source_database => 'db1.com',
destination_database => 'db2.com',
perform_actions => true,
bi_directional => false,
include_ddl => true,
instantiation => dbms_streams_adm.instantiation_table_network);
end;
在源庫執行MAINTAIN_TTS過程(表空間級)
檢查表空間的自包含
exec sys.dbms_tts.transport_set_check('TEST01',true,true);
select * from sys.transport_set_violations;
connect ;
declare
v_ts dbms_streams_tablespace_adm.tablespace_set;
begin
v_ts(1) := 'TEST01';
dbms_streams_adm.maintain_tts(
tablespace_names => v_ts,
source_directory_object => 'dir_db1',
destination_directory_object => 'dir_db2',
source_database => 'db1.com',
destination_database => 'db2.com',
perform_actions => true,
/*bi_directional => true,*/
include_ddl => true);
end;
3 如果在執行2的過程時失敗,需要清除指令碼
--select script_id from dba_recoverable_script;
--exec dbms_streams_adm.RECOVER_OPERATION('&1','PURGE');
declare
v_script_id varchar2(32);
begin
select script_id into v_script_id from dba_recoverable_script;
dbms_streams_adm.RECOVER_OPERATION(v_script_id,'PURGE');
exception
when no_data_found then
DBMS_OUTPUT.PUT_LINe('no data found') ;
when others then
3 如果在執行2的過程時失敗,需要清除指令碼
--select script_id from dba_recoverable_script;
--exec dbms_streams_adm.RECOVER_OPERATION('&1','PURGE');
declare
v_script_id varchar2(32);
begin
select script_id into v_script_id from dba_recoverable_script;
dbms_streams_adm.RECOVER_OPERATION(v_script_id,'PURGE');
exception
when no_data_found then
DBMS_OUTPUT.PUT_LINe('no data found') ;
when others then
DBMS_OUTPUT.PUT_LINe('error~!') ;
end;
4 說明,如果已經存在複製環境,再配置其它型別的複製將會導致失敗,所以配置複製前
需要清除已經存在的複製環境.
源與目標庫都做:
--exec dbms_streams_adm.REMOVE_STREAMS_CONFIGURATION;
begin
for cur_pro in (select propagation_name from dba_propagation) loop
dbms_propagation_adm.drop_propagation(cur_pro.propagation_name);
end loop;
dbms_streams_adm.REMOVE_STREAMS_CONFIGURATION;
end;
5 配置失敗,發現目標庫apply orror
select * from dba_apply;
select * from dba_apply_error;
6 完成stream的表空間複製
connect ;
dbms_capture_adm.prepare_schema_instantiation(schema_name => 'hs_his');
declare
v_scn number;
begin
v_scn := dbms_flashback.get_system_change_number();
(
source_schema_name => 'hs_his',
source_database_name => 'db1.com',
instantiation_scn => v_scn);
end;
http://dobzhu7781.spaces.live.com/blog/cns!4817887C779350C9!164.entry
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-629873/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle simple resource planOracle
- ORACLE STREAM ERROROracleError
- restart oracle streamRESTOracle
- Oracle stream案例分享Oracle
- oracle stream pool sizeOracle
- Oracle Stream概述與配置Oracle
- Oracle Stream Replication 技術Oracle
- oracle stream學習(一)Oracle
- Oracle Stream 深入探討Oracle
- oracle 10 g stream tableOracle
- Oracle Stream(2)--Streams功能Oracle
- Oracle Stream(1)--Streams概述Oracle
- oracle 10g table streamOracle 10g
- oracle 10g user streamOracle 10g
- oracle 10g stream weihuOracle 10g
- Install Oracle 10g on Solaris 10 simple recordOracle 10g
- oracle stream之schema級複製Oracle
- Oracle Stream配置詳細步驟Oracle
- Oracle Stream的安裝、配置和使用Oracle
- Oracle Stream實戰(9)—測試(二)Oracle
- Oracle Stream實戰(8)—測試(一)Oracle
- oracle 9i stream配置備記Oracle
- Oracle Stream(3)--Stream與高階複製和邏輯Dataguard的比較Oracle
- Oracle Stream實戰(10)—問題診斷Oracle
- 一步一步配置Oracle StreamOracle
- Java-stream(1) Stream基本概念 & Stream介面Java
- Shrio(Simple,Java,Security)Java
- django-simple-captchaDjangoAPT
- simple Terracotta session 同步Session
- SAP Simple FinanceNaN
- Simple definition of SAP productions
- Simple Neural Network
- Simple state transition 3
- Paxos Made Simple
- ORACLE10g Stream表級複製配置Oracle
- 最近幾天做oracle stream遇到很多問題Oracle
- 做oracle stream測試遇到 ORA-20446Oracle
- 單例項和RAC打造的ORACLE STREAM(完)單例Oracle