把Oracle單表流複製搞定,由於oracle stream 操作步驟多,之前遇到許多問題,
沒有理清思路或者說自己對此的理解不夠,所以失敗。對於重要表,流複製類似dataguard應用日誌,主伺服器
捕獲,然後傳遞,從伺服器接受,如此而以。簡單記錄一下主要步驟。
1 主伺服器 os: windows sid:rman 資料庫版本10.2.0.1
從伺服器 os: windows sid format 資料庫版本10.2.0.1
2 主、從資料庫分別執行如下的語句:
Sqlplus ‘/ as sysdba’
alter system set aq_tm_processes=2 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=25M scope=spfile;--這個我沒執行,理由是oracle自動分配了
alter system set utl_file_dir='*' scope=spfile;
alter system set open_links=4 scope=spfile;
3 主從機設定歸檔 mout狀態下alter database archivelog 另開啟alter system set log_archive_start=true;
查看歸檔是否成功select recid, name, first_time from v$archived_log;
4 主從機資料表空間和使用者
create tablespace stream_tbs datafile 'g:\oracle\oradata\rman\stream01.dbf' size 200m
autoextend on extent management local uniform size 1m segment space management auto;
資料表空間已建立。
-- 建立streams系統管理使用者,並授予dba許可權
JSSWEB> create user test identified by test default tablespace stream_tbs;
使用者已建立。
--將logminer的資料字典從system資料表空間轉移到建立的資料表空間,防止撐滿system資料表空間
execute dbms_logmnr_d.set_tablespace('tbs_stream');
-- 由於streams使用者操作需要較多許可權,此處僅用於示範,簡便期間直接授予dba許可權
授權test系統管理使用者
JSSWEB> grant dba to test;
begin
dbms_streams_auth.grant_admin_privilege(
grantee => 'test',
grant_privileges => true);
end;
5 主從機資料表空間和使用者
create tablespace stream_tbs datafile 'd:\oracle\oradata\rman\stream01.dbf' size 200m
autoextend on extent management local uniform size 1m segment space management auto;
資料表空間已建立。
-- 建立streams系統管理使用者,並授予dba許可權
JSSWEB> create user strmadmin identified by strmadmin default tablespace stream_tbs;
使用者已建立。
--將logminer的資料字典從system資料表空間轉移到建立的資料表空間,防止撐滿system資料表空間
execute dbms_logmnr_d.set_tablespace('tbs_stream');
-- 由於streams使用者操作需要較多許可權,此處僅用於示範,簡便期間直接授予dba許可權
授權test系統管理使用者
JSSWEB> grant dba to strmadmin ;
begin
dbms_streams_auth.grant_admin_privilege(
grantee => 'strmadmin',
grant_privileges => true);
end;
6 配置網路連接
主要資料庫(tnsnames.ora)中添加從資料庫的配置。
RMAN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))
)
(CONNECT_DATA =
(SID = rman)
(SERVER = DEDICATED)
)
)
配置從環境tnsnames.ora
從資料庫(tnsnames.ora)中添加主要資料庫的配置。
FORMAT =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.104)(PORT = 1521))
)
(CONNECT_DATA =
(SID = format)
(SERVER = DEDICATED)
)
)
7 建立database link
主:create database link format connect to strmadmin identified by strmadmin using 'format';
從:create database link rman connect to strmadmin identified by strmadmin using 'rman ';
然後相互tnsping 或 select sysdate from dual@format/rman;
8 主庫 exec dbms_streams_adm.set_up_queue();
從庫 exec dbms_streams_adm.set_up_queue();
9 建立捕獲規則
begin
dbms_streams_adm.add_table_rules(
table_name => 'scott.emp',
streams_type => 'capture',
streams_name =>'capture_stream',
queue_name => 'test.streams_queue',
include_dml => true,
include_ddl => true,
inclusion_rule => true);
end;
--建立傳播規則
begin
dbms_streams_adm.add_table_propagation_rules(
table_name =>'scott.emp',
streams_name => 'sour_to_targ',
source_queue_name =>'test.streams_queue',
destination_queue_name => 'strmadmin.streams_queue@format',
include_dml => true,
include_ddl => true,
source_database =>'rman',
inclusion_rule => true,
queue_to_queue => true);
end;
select capture_name,status from dba_capture;
CAPTURE_NAME STATUS
------------------------------ --------
CAPTURE_STREAM DISABLED