Stream单表复制:分步实施,本地捕获

 linux6.3,oracle 11g r2,Stream单表复制:分步实施,本地捕获

1.     准备工作

分步实施,做一本地捕获的单表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

 

 

1.1. 在所有的database上部署管理用户

应当创建一个新用户和表空间,不应用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;

/

1.2. 配置网络连接和database links

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

1.3. 保证两端archivelog模式

 

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

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 shared_pool_size=100m scope=both;

alter system set open_links=4 scope=spfile;

alter system set timed_statistics= TRUE scope=spfile;

2.     设置stream
1.1. 创建流队列。

源库发送队列

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;

/

1.2. 在源数据库上创建捕获进程

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;

/     

1.3. 源数据库上创建传播进程

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;

/  

1.4. 在目标数据库创建应用进程:

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;

/   

1.5. 将源数据中的表同步目标数据库

conn strmadmin/strmadmin@strmt1

create table scott.test1 as select * from scott.test1@strms1;

1.6. 在目标数据库上设置应用进程开始执行的SCN

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;

/

1.7. 在目标数据库上启动应用进程

conn strmadmin/strmadmin@strmt1;

exec dbms_apply_adm.start_apply('apply_strmt1');

1.8. 在源数据库启用捕获进程

conn strmadmin/strmadmin@strms1;

exec dbms_capture_adm.start_capture('capture_strms1');     

1.9. 测试:

在源库test1上作DML操作,在目标库看相应变化,第一次同步较慢,需要20s,之后同步很快,手工切换查看时已经同步好。   

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值