用stream在Schema级实现数据复制

rhel6.3,oracle 11203,用stream在Schema级实现数据复制

 

1.准备工作


 

 

源端(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

1.2. 配置网络连接和database links

网络配置已经做好,而且简单,不再做说明,只做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';

1.3. 保证两端archivelog模式

检查

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

1.4. 检查密码文件是否存在

源端和目标端都需要密码文件,没有就手工创建,或从一端拷贝到另一端。有了密码文件以及相应参数(remote_login_passwordfile)正确,就可以远程以sys用户登陆,此过程没有完成会影响日志文件的传输。

1.5. 设置初始化参数

所有库都需要改的

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;

2.stream配置
2.1. 创建流队列

源端流队列

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;

/

2.2. 创建捕获进程

源端捕获进程,在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;

/

2.3. 创建传播进程

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;

/

2.4. 创建应用进程

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;

/

 

2.5. 启动capture

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;

/

2.6. 实例化复制数据库

[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

2.7. 启动Apply进程

connect strmadmin/strmadmin@dwh02

begin

dbms_apply_adm.start_apply(

apply_name => 'apply_dwh02');

end;

/

 

3.测试

在源端hr用户下做一些DMLDDL操作进行测试。

具体是在dwh01HR用户下创建表,插入,删除,删除表的操作,在DWH02下查看相应的变化。发现数据能够同步。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值