分步实施,做一本地捕获的单表stream复制。
|
源端(source database) |
目标端(destination database) |
|
Hostname |
Rhel63db |
Tan63rep |
|
Db_name |
Strms1 |
Strmt1 |
|
Gblobal_name |
Strms1 |
Strmt1 |
|
Instance_name |
Strms1 |
Strmt1 |
|
Db_unique_name |
Strms1 |
Strmt1 |
|
应当创建一个新用户和表空间,不应用sys,system用户,system系统表空间。
SQL> create tablespace streamtbs datafile
'/data01/apps/oracle/oradata/strms1/streamtbs01.dbf' size 50m
autoextend on maxsize unlimited segment space management auto;
将logminer的数据字典从system分离,防止撑满system表空间
SQL> execute dbms_logmnr_d.set_tablespace('streamtbs');
SQL> create user strmadmin identified by strmadmin default tablespace streamtbs;
SQL> grant dba to strmadmin;
1. The DBA role is required for a user to create or altercapture processes, synchronous captures, and apply processes. When the user does not need to perform these tasks,DBA role can be revoked from the user.
用GRANT_ADMIN_PRIVILEGE给一些特有权限
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'strmadmin',
grant_privileges => TRUE);
END;
/
网络配置已经做好,而且简单,不再做说明,只做database link部分
每个dblink必须用 streams administrator’s chema (就是前面创建的strmadmin)
源端(source database):
SQL> conn strmadmin/strmadmin
create database link strmt1 connect to strmadmin
identified by strmadmin using 'strmt1';
Database link created.
目标端(destination database)
SQL> conn strmadmin/strmadmin
create database link strms1 connect to strmadmin
identified by strmadmin using 'strms1';
mkdir -p /u01/strms1/arch
alter system set log_archive_dest_1='location=/u01/strms1/arch' scope=both;
mkdir -p /u01/strmt1/arch
alter system set log_archive_dest_1='location=/u01/strmt1/arch' scope=both;
检查
SQL> conn /as sysdba
Connected.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/strms1/arch1
Oldest online log sequence 1
Next log sequence to archive 2
源端和目标端都需要密码文件,目标端需要从源端拷贝。有了密码文件以及相应参数(remote_login_passwordfile)正确,就可以远程以sys用户登陆,此过程没有完成会影响日志文件的传输。
所有库都需要改的
alter system set aq_tm_processes=2 scope=both;
alter system set global_names=true scope=both;
alter system set undo_retention=3600 scope=both;
alter system set job_queue_processes=10 scope=both;
alter system set parallel_max_servers=20 scope=both;
alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;
alter system set streams_pool_size=100M scope=spfile;
alter system set shared_pool_size=100m scope=both;
alter system set open_links=4 scope=spfile;
alter system set timed_statistics= TRUE scope=spfile;
源库发送队列
conn strmadmin/strmadmin@strms1;
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE(
queue_table => 'strms1_table',
queue_name => 'strms1_queue',
queue_user => 'strmadmin');
END;
/
备库接收队列
conn strmadmin/strmadmin@strmt1;
BEGIN
DBMS_STREAMS_ADM.SET_UP_QUEUE(
queue_table => 'strmt1_table',
queue_name => 'strmt1_queue',
queue_user => 'strmadmin');
END;
/
conn strmadmin/strmadmin@strms1;
begin
dbms_streams_adm.add_table_rules(
table_name => 'scott.test1',
streams_type => 'capture',
streams_name => 'capture_strms1',
queue_name => 'strmadmin.strms1_queue',
include_dml => true,
include_ddl => true,
inclusion_rule => true);
end;
/
conn strmadmin/strmadmin@strms1;
begin
dbms_streams_adm.add_table_propagation_rules(
table_name => 'scott.test1',
streams_name => 'strms1_to_strmt1',
source_queue_name => 'strmadmin.strms1_queue',
destination_queue_name => 'strmadmin.strmt1_queue@strmt1',
include_dml => true,
include_ddl => true,
source_database => 'strms1',
inclusion_rule => true,
queue_to_queue => true);
end;
/
conn strmadmin/strmadmin@strmt1
begin
dbms_streams_adm.add_table_rules(
table_name => 'scott.test1',
streams_type => 'apply',
streams_name => 'apply_strmt1',
queue_name => 'strmadmin.strmt1_queue',
include_dml => true,
include_ddl => true,
source_database => 'strms1',
inclusion_rule => true);
end;
/
conn strmadmin/strmadmin@strmt1
create table scott.test1 as select * from scott.test1@strms1;
conn strmadmin/strmadmin@strmt1
DECLARE
source_scn NUMBER;
BEGIN
source_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN@strmt1(
source_object_name=> 'scott.test1',
source_database_name=> 'strms1',
instantiation_scn=> source_scn);
END;
/
conn strmadmin/strmadmin@strmt1;
exec dbms_apply_adm.start_apply('apply_strmt1');
conn strmadmin/strmadmin@strms1;
exec dbms_capture_adm.start_capture('capture_strms1');
在源库test1上作DML操作,在目标库看相应变化,第一次同步较慢,需要20s,之后同步很快,手工切换查看时已经同步好。