|
源端(source database) |
目标端(destination database) |
|
Hostname |
Rhel63db |
Tan63rep |
|
Db_name |
Dwh01 |
Dwh02 |
|
Gblobal_name |
Dwh01 |
Dwh02 |
|
Instance_name |
Dwh01 |
Dwh02 |
|
Db_unique_name |
Dwh01 |
Dwh02 |
|
1.1. 在所有的database上部署管理用户
应当创建一个新用户和表空间,不应用sys,system用户,system系统表空间。
SQL> create tablespace streamtbs datafile
'/data01/apps/oracle/oradata/dwh01/streamtbs01.dbf' size 100m
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. TheDBA 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;
/
或
SQL> CREATE DIRECTORY strms_dir AS '/u01/admin';
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'strmadmin',
grant_privileges => FALSE,
file_name => 'grant_strms_privs.sql',
directory_name => 'strms_dir');
END;
/
SET ECHO ON
SPOOL /u01/admin/grant_strms_privs.out
@/u01/admin/grant_strms_privs.sql
SPOOL OFF
网络配置已经做好,而且简单,不再做说明,只做database link部分
每个dblink必须用 streams administrator’s chema (就是前面创建的strmadmin)
源端(source database):
SQL> conn strmadmin/strmadmin
Connected.
SQL> create database link dwh02 connect to strmadmin
2 identified by strmadmin using 'dwh02';
Database link created.
目标端(destination database)
SQL> conn strmadmin/strmadmin
Connected.
SQL> create database link dwh01 connect to strmadmin
identified by strmadmin using 'dwh01';
检查
SQL> conn /as sysdba
Connected.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/arch/
Oldest online log sequence 132
Next log sequence to archive 134
Current log sequence 134
源端和目标端都需要密码文件,没有就手工创建,或从一端拷贝到另一端。有了密码文件以及相应参数(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 open_links=4 scope=spfile;
alter system set LOG_ARCHIVE_DEST_STATE_2=enable scope=both;
alter system set timed_statistics= TRUE scope=spfile;
源端流队列
connect strmadmin/strmadmin@dwh01
begin
dbms_streams_adm.set_up_queue(
queue_table => 'dwh01_queue_table',
queue_name => 'dwh01_queue');
end;
/
目标端
connect strmadmin/strmadmin@dwh02
begin
dbms_streams_adm.set_up_queue(
queue_table => 'dwh02_queue_table',
queue_name => 'dwh02_queue');
end;
/
源端捕获进程,在hr用户上操作。
connect strmadmin/strmadmin@dwh01
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'hr',
streams_type => 'capture',
streams_name => 'capture_dwh01',
queue_name => 'strmadmin.dwh01_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
/
connect strmadmin/strmadmin@dwh01
begin
dbms_streams_adm.add_schema_propagation_rules(
schema_name => 'hr',
streams_name => 'dwh01_to_dwh02',
source_queue_name => 'strmadmin.dwh01_queue',
destination_queue_name => 'strmadmin.dwh02_queue@dwh02',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'dwh01',
inclusion_rule => true);
end;
/
connect strmadmin/strmadmin@dwh02
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'hr',
streams_type => 'apply',
streams_name => 'apply_dwh02',
queue_name => 'strmadmin.dwh02_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'dwh01',
inclusion_rule => true);
end;
/
connect strmadmin/strmadmin@dwh01
set serveroutput on
declare
v_scn number;
begin
select current_scn into v_scn from v$database;
dbms_output.put_line('Current_SCN:'||v_scn);
dbms_capture_adm.start_capture(
capture_name => ' capture_dwh01');
end;
/
[oracle@rhel63db ~]$ expdp system/system@dwh01 directory=strms_dir schemas=hr dumpfile=dumpschema_hr.dmp logfile=expdp.log flashback_scn=5559555
[oracle@rhel63db ~]$ impdp system/system@dwh02 directory=strms_dir schemas=hr dumpfile=dumpschema_hr.dmp logfile=impdp.log streams_configuration=y
connect strmadmin/strmadmin@dwh02
begin
dbms_apply_adm.start_apply(
apply_name => 'apply_dwh02');
end;
/
在源端hr用户下做一些DML和DDL操作进行测试。
具体是在dwh01的HR用户下创建表,插入,删除,删除表的操作,在DWH02下查看相应的变化。发现数据能够同步。