<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<span style="background-color:inherit;line-height:1.5;">Oracle Stream概述与配置 </span>
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
介绍一下Streams和goldengate的比较
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
1.异构复制
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
streams 仅支持oracle-oracle
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG 支持不同平台的复制
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
2.capture方式
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
streams 通过logmnr的方式抽取redo和archivelog中的数据,效率相比更低一些
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG 通过GG独有的方式抽取内存、redo、archivelog中数据,效率相比更高一些
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
3.收集数据
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
streams Oracle专有后台进程
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG 外部进程(extract/replicat)
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
4.内存分配
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Streams SGA(stream pool)
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG OS memory
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
5.事务 – 数据收集阶段(源数据库)
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Streams 所有的事务(commit,uncommited)
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG 提交的事务
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
6.数据应用阶段(目标数据库)
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Sreams 过滤掉uncommited数据
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG 收到的数据都是提交过的,直接应用。
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
7.事务的顺序
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Streams SCN的顺序
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
GG commit先后顺序
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
下面进行1个DEMO演示Stream配置部署:
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step1. 参数配置
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Source-Target:
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<span style="background-color:inherit;line-height:1.5;">archive log listalter system set aq_tm_processes=2 scope=both; alter system set streams_pool_size=200M scope=spfile; alter database add supplemental log data;alter system set "_job_queue_interval"=1 scope=spfile;startup force; </span>
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step2. 创建Streams管理用户
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Source-Target:
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
create tablespace tbs_stream datafile size 100M;create user strmadmin identified by strmadmin default tablespace tbs_stream;grant dba to strmadmin;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step3. 创建业务用户
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Source-Target:
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
create tablespace tianbaobao datafile size 100M;create user tianbaobao identified by tianbaobao default tablespace tbs_stream;grant dba to tianbaobao;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step4. 配置环境tnsnames.ora
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Source-Target:
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SOURCEDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = source.ht8888.ht3)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = sourcedb) ) )
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
TARGETDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = target.ht8888.ht3)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = targetdb) ) )
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step5.创建DBlink(如果不配置双向复制,无需配置目标到源的DBlink)
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
create database link strm_link connect to strmadmin identified by strmadmin using 'targetdb';
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step6.创建Streams Queue
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Source-Target:
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
sqlplus strmadmin/strmadmin@sourcedbbegin dbms_streams_adm.set_up_queue( queue_table => 'source_queue_table', queue_name => 'source_queue'); end; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
sqlplus strmadmin/strmadmin@targetdbbegin dbms_streams_adm.set_up_queue( queue_table => 'target_queue_table', queue_name => 'target_queue'); end; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step7.源创建捕获进程
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@sourcedbbegin dbms_streams_adm.add_schema_rules(schema_name => 'tianbaobao', streams_type => 'capture', streams_name => 'capture_source', queue_name => 'strmadmin.source_queue', include_dml => true, include_ddl => true, inclusion_rule => true); end; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step8.源创建传播进程
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@sourcedbbegin dbms_streams_adm.add_schema_propagation_rules( schema_name => 'tianbaobao', streams_name => 'source_to_target', source_queue_name => 'strmadmin.source_queue', destination_queue_name => 'strmadmin.target_queue@strm_link', include_dml => true, include_ddl => true, source_database => 'sourcedb', inclusion_rule => true,queue_to_queue => true); end; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
#修改propagation休眠时间为0,表示实时传播LCR。
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@sourcedbbegin dbms_aqadm.alter_propagation_schedule( queue_name => 'source_queue', destination => 'strm_link', destination_queue => 'target_queue',latency => 0); end; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step9.目标创建应用进程
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@sourcedbbegin dbms_streams_adm.add_schema_rules( schema_name => 'tianbaobao', streams_type => 'apply', streams_name => 'apply_target', queue_name => 'strmadmin.target_queue', include_dml => true, include_ddl => true, source_database => 'sourcedb', inclusion_rule => true); end; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step10.数据库直接设置SCN的方式进行实例化
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
---获取源库互置用户的SCN
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@sourcedb set serveroutput on DECLARE iscn NUMBER;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
-- Variable to hold instantiation SCN valueBEGIN iscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER(); DBMS_OUTPUT.PUT_LINE ('Instantiation SCN is: ' || iscn);END; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
---设置为目标库互置用户的SCN
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect streamadmin/streamadmin@targetdbBEGIN DBMS_APPLY_ADM.SET_SCHEMA_INSTANTIATION_SCN( source_schema_name => 'TIANBAOBAO', source_database_name => 'SOURCEDB', instantiation_scn => &iscn);END; /
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step11.启动捕获和应用进程
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@sourcedbexec dbms_capture_adm.start_capture(capture_name => 'capture_source');
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
connect strmadmin/strmadmin@targetexec dbms_apply_adm.start_apply(apply_name => 'apply_target');
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step12.创建测试表进程测试
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Source:sqlplus tianbaobao/tianbaobao@sourcedbSQL> create table tb30(x int);
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Table created.
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL> insert into tb30 values (1);
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
1 row created.
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL> commit;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Commit complete.
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL> alter table tb30 add y int ;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Table altered.
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL> insert into tb30 values (2,2);
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
1 row created.
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL> commit;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Commit complete.
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL>
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
Traget:sqlplus tianbaobao/tianbaobao@targetdbSQL> select * from tb30;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
X Y---------- ---------- 1 2 2
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
SQL>
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
<br style="background-color:inherit;" />
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
step13 .常用命令
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
select CAPTURE_NAME,QUEUE_NAME,STATUS,CAPTURED_SCN,APPLIED_SCN from dba_capture;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
select PROPAGATION_NAME,SOURCE_QUEUE_OWNER,SOURCE_QUEUE_NAME,DESTINATION_QUEUE_NAME,DESTINATION_DBLINK,STATUS from dba_propagation;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
select APPLY_NAME,ERROR_NUMBER,STATUS from dba_apply;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
select APPLY_NAME,QUEUE_NAME,MESSAGE_NUMBER,ERROR_NUMBER,ERROR_MESSAGE from dba_apply_error;
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
exec dbms_capture_adm.stop_capture(capture_name => 'capture_source');
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
exec dbms_apply_adm.stop_apply(apply_name => 'apply_target');
</div>
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;">
exec DBMS_STREAMS_ADM.remove_streams_configuration();
</div>
<div>
<br />
</div>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31520497/viewspace-2156757/
,如需转载,请注明出处,否则将追究法律责任。