Oracle數據庫10gR2中stream多源復制方法
在10gR2中,oracle簡化了stream的配置的全過程,在9iR2及10gR1中,需要針對stream的捕獲、傳播、應用進程進行配置的步驟
已經被dbms_streams_adm新提供的過程(pre_instantiation_setup/post_instantiation_setup)給封裝起來啦,
配置stream只需要調用兩個存儲過程就可以搞定啦,真是太激動人心啦,下面簡單地介紹一下dbms_streams_adm的新過程的用法。
1.在stream進行配置前,需要做些準備工作
a 源庫與目標庫初始化參數的設置
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 strmadminpw
default tablespace &tbs_name quota unlimited on &tbs_name;
grant connect, resource, dba to strmadmin;
d 源庫與目標庫創建互連的數據鏈
connect strmadmin/strmadminpw@test96
create database link test99.net connect to strmadmin
identified by strmadminpw using 'test99';
connect strmadmin/strmadminpw@test99
create database link test96.net connect to strmadmin
identified by strmadminpw using 'test96';
說明:必須確保雙方的數據庫鏈是可以連通.
用pre_instantiation_setup/post_instantiation_setup過程時
db link必須用db_name.domain的格式
e 源庫與目標庫必須處于歸檔模式
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
2.執行pre_instantiation_setup過程
在調用dbms_streams_adm的pre_instantiation_setup/post_instantiation_setup過程時, 它們必須成對出現,pre_instantiation_setup過程中,maintain_mode參數可取GLOBAL與 TRANSPORTABLE TABLESPACES,如果取GLOBAL時,表示全庫復制,否則可以定義需要復制的表空間; perform_actions參數為TRUE,進行配置產生的源腳本將記錄在dba_recoverable_*字典表, 如果pre_instantiation_setup執行時遇到錯誤,可以通過執行dbms_steams_adm的
recover_operation過程 在更正錯誤后繼續執行復制配置; source_database/destination_database是我們已經創建好的dblink,必須確保正確啊, 否則pre_instantiation_setup過程將會失敗,報ORA-23621錯誤,解決辦法在后面會介紹; bi_directional參數設置為true時,表示是多源復制,即目標與源庫雙向同步, 否則即只從源庫向目標庫同步數據; exclude_schemas參數指需要排除在全庫同步的表空間,多個表空間的話用逗號分開,
*表示排除配置stream時庫中已經存在的表空間;
start_processes參數指配置完成后啟動捕獲及應用進程。
SQL>connect strmadmin/strmadminpw@test96
declare
empty_tbs dbms_streams_tablespace_adm.tablespace_set;
begin
dbms_streams_adm.pre_instantiation_setup(
maintain_mode => 'GLOBAL',
tablespace_names => empty_tbs,
source_database => 'test96.net',
destination_database => 'test99.net',
perform_actions => true,
bi_directional => true,
include_ddl => true,
start_processes => true,
exclude_schemas => 'WMSYS,STRMADMIN,DBSNMP,TSMSYS,',
exclude_flags => dbms_streams_adm.exclude_flags_unsupported +
dbms_streams_adm.exclude_flags_dml + dbms_streams_adm.exclude_flags_ddl);
end;
/
如果參與復制的源庫與目標庫的db link等配置的正確,該過程將成功結束,
并且在strmadmin模式創建一系統用于復制的隊列與字典表,如果db link配置出錯,
執行pre_instantiation_setup過程時,將會報如下錯誤:
ORA-23621: Operation corresponding
3.用rman復制源庫到目標庫
a 對源庫用rman進行備份,拷貝備份集與產生的歸檔到目標庫,
并將目標庫down下來,啟動nomount狀態。
rman nocatalog target /
rman>backup database;
rman>sql'alter system archive log current';
b 求得源庫的scn
SQL>connect strmadmin/strmadminpw@test96
SQL>set serveroutput on size 1000000
SQL>declare
until_scn number;
begin
until_scn:= dbms_flashback.get_system_change_number;
dbms_output.put_line('until scn: '||until_scn);
end;
/
until scn: 429596
c 用rman將源庫復制到目標庫
rman nocatalog target /
rman> connect auxiliary sys/sys@test99
rman> run
{
set until scn 429596;
duplicate target database to 'TEST'
nofilenamecheck
open restricted;
}
d 重新命名目標庫的global_name
alter database rename global_name to test99.net;
e 重新創建目標庫的db link
connect strmadmin/strmadminpw@test99
create database link test96.net connect to strmadmin
identified by strmadminpw using 'test96';
4.執行post_instantiation_setup過程
post_instantiation_setup也在源庫執行,需要注意的參數是instantiation_scn
它的取值是我們從源庫上獲的scn的值-1=429595.
SQL>connect strmadmin/strmadminpw@test96
SQL>declare
empty_tbs dbms_streams_tablespace_adm.tablespace_set;
begin
dbms_streams_adm.post_instantiation_setup(
maintain_mode => 'GLOBAL',
tablespace_names => empty_tbs,
source_database => 'test96.net',
destination_database => 'test99.net',
perform_actions => true,
bi_directional => true,
include_ddl => true,
start_processes => true,
instantiation_scn => 429595,
exclude_schemas => '*',
exclude_flags => dbms_streams_adm.exclude_flags_unsupported +
dbms_streams_adm.exclude_flags_dml + dbms_streams_adm.exclude_flags_ddl);
end;
/
在目標庫禁止restricted session
SQL>connect sys/sys@test99.net as sysdba
SQL>alter system disable restricted session;
5.測試stream的配置結果
a 在test96上創建一個schema,并在該schema下創建一些對象,可以在test99上看到
b 在test99上創建一個schema,并在該schema下創建一些對象,可以在test96上看到
6 關于雙向復制中avoid change cycling
查看目標庫apply進程的tag:
COLUMN APPLY_NAME HEADING 'Apply Process Name' FORMAT A30
COLUMN APPLY_TAG HEADING 'Tag Value' FORMAT A30
SQL>connect sys/sys@test99 as sysdba;
SELECT APPLY_NAME, APPLY_TAG FROM DBA_APPLY;
Apply Process Name Tag Value
------------------------------ -----------
APPLY$_TEST96_42 010781
查看源庫apply進程的tag:
COLUMN APPLY_NAME HEADING 'Apply Process Name' FORMAT A30
COLUMN APPLY_TAG HEADING 'Tag Value' FORMAT A30
SQL>connect sys/sys@test99 as sysdba;
SELECT APPLY_NAME, APPLY_TAG FROM DBA_APPLY;
Apply Process Name Tag Value
------------------------------ ------------------------------
APPLY$_TEST99_15 010498
說明:消除多源復制中的遞歸問題,stream中已經有很好的消除機制,
源端正常作業寫入的redo entry的tag是NULL的,如果是由于源端的apply進程
產生的redo entry,在redo entry中將帶有tag標志,這樣在源端捕獲進程在
捕獲的redo entry中,過慮掉tag是NULL的,然后就可以消除change cycling.
10gR2stream全庫復制
以上主要為大家介紹了pre_instantiation_setup/post_instantiation_setup過程在配置全庫復制的方法,以下介紹dbms_streams_adm的maintain_global過程如何配置stream全庫復制方法,適用于10gR2及以后版本。
1l.在stream進行配置前,需要做些準備工作
a 源庫與目標庫初始化參數的設置
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 strmadminpw
default tablespace &tbs_name quota unlimited on &tbs_name;
grant connect, resource, dba to strmadmin;
d 源庫與目標庫創建互連的數據鏈
connect strmadmin/strmadminpw@test96
create database link test99.net connect to strmadmin
identified by strmadminpw using 'test99';
connect strmadmin/strmadminpw@test99
create database link test96.net connect to strmadmin
identified by strmadminpw using 'test96';
說明:必須確保雙方的數據庫鏈是可以連通.
用pre_instantiation_setup/post_instantiation_setup過程時
db link必須用db_name.domain的格式
e 源庫與目標庫必須處于歸檔模式
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
f 源庫與目標庫必須創建directory
create directory dir_test96 as '/home/oracle/worksh';
create directory dir_test99 as '/home/oracle/worksh';
2.在源庫執行MAINTAIN_GLOBAL過程
SQL>connect strmadmin/strmadminpw@test96
begin
dbms_streams_adm.maintain_global(
source_directory_object => 'dir_test96',
destination_directory_object => 'dir_test99',
source_database => 'test96.net',
destination_database => 'test99.net',
perform_actions => true,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_FULL_NETWORK);
end;
說明:在執行maintain_global時,源庫與目標庫必須創建directory,然后在源庫執行, 目標庫幾乎什么都不用做,stream環境已經配置完畢。