常识:
Stream是oracle的消息队列(也叫oracle Advanced Queue)技术的一种扩展应用。Oracle的消息队列和其他队列产品功能类似,都是通过发布/订阅的方式来解决事件管理。流复制(Stream Replication)是基于消息队列的一个数据共享技术,他可以实现两个数据库之间数据库级、Schema级、table级的数据同步,并且这种同步可以是双向的。
Oracle高级复制(Oracle Advanced Replication)和流复制,前者是基于触发器的,后者是基于日志挖掘(Logminer)的,不一样的。
工作原理:
Stream搜集事件、把事件保存在队列中,然后把事件发送给不同的订阅者。
流复制:在源数据库有一个捕获进程(Capture Process),该进程利用Logminer技术从日志中提取DDL、DML语句(逻辑变更记录 LCR,一个LCR对应一个院子的行变更)。这些LCR会保存到源数据库的发送队列中,然后传播进程将这些LCR发送到目标数据库的接受队列,目标数据库根据LCR实现数据同步。
Streams 与 Data Guard
主要是为了数据共享 为了灾难恢复和高可用性
可以多方向同步 只能是单向的 primary->standby
粒度可以使数据库 schema 只能是数据库级别
table三个级别
支持异种平台间的同步 必须同种平台
参与复制的每个数据库都可以读写 只有primary可以读写,standby只能读
支持oracle和非oracle数据库间同步 只能是oracle间
配置流:
1.在source和target的tnsnames.ora都配置上对方的连接
2.修改数据库global_name如
源:alter database rename global_name to source.test.com.cn
目标:alter database rename global_name to target.test.com.cn
3.修改其他参数:
源数据库:
global_name=true
aq_tm_processes=2
job_queue_processes=10
logmnr_max_persistent_sessions=1
open_links=4
db_domain=test.com.cn
service_names=source.test.com.cn
目标数据库:
global_name=true
aq_tm_processes=2
job_queue_processes=10
logmnr_max_persistent_sessions=1
open_links=4
db_domain=test.com.cn
service_names=target.test.com.cn
4.在源数据库上创建到目的数据库的连接:
create database link target.test.com.cn connect to user identified by pwd using 'target_tns';
5.在源数据库上创建source队列:
begin
dbms_streams_adm.set_up_queue(
queue_table=>'source_queue_table',
queue_name=>'source_queue');
end;
6.在源数据库上创建capture进程:
dbms_streams_adm.add_schema_rules(
schema_name=>'product',
streams_type=>'capture',
streams_name=>'source_capture_stream',
queue_name=>'source_queue',
include_dml=>true,
include_dll=>true,
include_tagged_lcr=>false,
source_database=>null,
inclusion_rule=>true
);
end;
7.在源数据库上创建传播进程:
begin
dbms_streams_adm.add_schema_propagation_rules(
schema_name=>'product',
streams_name=>'propagation_product',
source_queue_name=>'test.source_queue', destination_queue_name=>'test.target_queue@target.test.com.cn',
include_dml=>true,
include_ddl=>true,
include_tagged_lcr=>false,
source_database=>'source.test.com.cn',
inclusion_rule=>true
);
end;
8.在目标数据库创建接受队列
begin
dbms_streams_adm_set_up_queue(
queue_table=>'target_queue_table',
queue_name=>'target_queue'
);
end;
9.创建apply进程:
begin
dbms_streams_adm.add_schema_rules(
schema_name=>'product',
streams_type=>'apply',
streams_name=>'target_apply_stream',
queue_name=>'target_queue',
include_dml=>true,
inlucde_ddl=>true,
inlucde_tagged_lcr=>false,
source_database=>'source.test.com.cn',
inclusion_rule=>true
);
end;
10.启动apply:
begin
dbms_apply_adm.start_apply(apply_name=>'target_apply_stream');
end;
11.从源数据库上导出数据:
exp user/pwd wner=product object_consistent=y file=product.exp grants=y
rows=y commit=y streams_instantiation=y
12.在目标数据库上导入数据:
imp user/pwd fromuser=product touser=product file=product.exp constraints=y ignore=y grants=y rows=y commit=y streams_instantiation=y
13.在源数据库上启动capture:
begin
dbms_capture_adm.start_capture (capture_name=>'source_capture_stream');
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11417069/viewspace-683773/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/11417069/viewspace-683773/