简单的流复制实验,bug还不是一般的多,10.2.0.1到10.2.0.4都试过了。一共碰上7个bug,看来只能在小应用上玩玩了,patch需要尽量打全,有的人可能找不到opatch在哪里,其实现在opatch不需要下载,都是自带的,就在$ORACLE_HOME下的OPatch
[@more@]使用local捕捉的话,虽然可以减少网络流量,但是增加了解析的消耗,加大了主库负担,同时在配置失败或者出问题时,维护比较麻烦,所以综合来说(不考虑bug因素)还是使用downstream要好。
首先2个库必须配置tnsnames,保证互相可以连接,主库必须启用归档,辅库如果使用arch传输的非real-time apply的downstream,可以不用归档,但如果要启用实时的apply,必须使用归档模式。local stream模式的情况下,副库不需要设置归档,主库甚至连log_archive_dest_2也不需要配置。复制的表最好都有主键,不然stream光依靠SUPPLEMENTAL LOG DATA似乎很容易崩溃。。。
其次要设置:
alter system set global_names=TRUE scope=both;
alter system set "_job_queue_interval"=1 scope=spfile;
alter system set aq_tm_processes=1;
alter system set streams_pool_size=200m scope=both;
至于open_links,job_queue_processes等要看实际站点数决定是否修改
注意streams_pool_size一定要够大,因为如果启用了SGA_TARGET,ORACLE可能分配很少内存给stream导致大量信息被spill到磁盘导致查询DBA_APPLY,DBA_CAPTURE,DBA_PROPGATION全部状态ENABLED但就是没有数据被同步。
同时设置_job_queue_interval也是为了提高队列检查时间,防止apply出问题。
主库:
用sys发布下面的命令:
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
grant dba to stadm identified by stadm;
exec DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE('STADM');
alter database rename global_name to JIAOYOU.COM;
create public database link test.com using 'test';
alter system set log_archive_dest_2='service=test arch noregister' scope=both;
这里注意每个词之间都是一个空格,多了可能发生不能识别的问题,如果是real-time apply的话:
alter system set log_archive_dest_2='service=test lgwr async noregister' scope=both;
副库:
用sys发布下面的命令:
grant dba to stadm identified by stadm;
exec DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE('STADM');
alter database rename global_name to TEST.COM;
create public database link jiaoyou.com using 'jiaoyou';
接下来使用stadm到主库:
create directory dir_source as '/u01/source';
create database link test.com connect to stadm identified by stadm using 'test';
接下来使用stadm到副库:
create directory dir_dest as '/u01/dest'
create database link jiaoyou.com connect to stadm identified by stadm using 'jiaoyou';
然后用stadm在2边的数据库执行select * from global_name@对方的global_name;
如果能显示表示没有问题。
接下来使用stadm到副库:
BEGIN
DBMS_STREAMS_ADM.MAINTAIN_SCHEMAS(
schema_names => 'SKY',
source_directory_object => 'DIR_SOURCE',
destination_directory_object => 'DIR_DEST',
source_database => 'JIAOYOU.COM',
destination_database => 'TEST.COM',
perform_actions => true,
dump_file_name => 'SKY.dmp',
capture_queue_table => 'rep_capture_queue_table',
capture_queue_name => 'rep_capture_queue',
capture_queue_user => NULL,
apply_queue_table => 'rep_dest_queue_table',
apply_queue_name => 'rep_dest_queue',
apply_queue_user => NULL,
capture_name => 'capture_sky',
propagation_name => 'prop_sky',
apply_name => 'apply_sky',
log_file => 'export_sky.clg',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_SCHEMA);
END;
/
上面的DBMS_STREAMS_ADM.MAINTAIN_SCHEMAS如果在主库上执行,就成为了local stream复制。downstream环境中,capture,propagation,apply都在复制节点上运行,而local stream时,apply在复制节点,capture和propagation则在主节点上,查询情况时不要搞错.如果配置成一个local stream,以后还要添加一个local stream的复制站点的话,只需要配置好复制站点,然后把queue和capture,propagation,apply的名字改掉:
BEGIN
DBMS_STREAMS_ADM.MAINTAIN_SCHEMAS(
schema_names => 'SKY',
source_directory_object => 'DIR_SOURCE',
destination_directory_object => 'DIR_DEST',
source_database => 'primary.COM',
destination_database => 'membj.COM',
perform_actions => true,
dump_file_name => 'SKY.dmp',
capture_queue_table => 'n_rep_cap_queue_table',
capture_queue_name => 'n_rep_cap_queue',
capture_queue_user => NULL,
apply_queue_table => 'n_rep_dest_queue_table',
apply_queue_name => 'n_rep_dest_queue',
apply_queue_user => NULL,
capture_name => 'capturenew_sky',
propagation_name => 'propnew_sky',
apply_name => 'applynew_sky',
log_file => 'export_sky.clg',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_SCHEMA);
END;
/
就可以看到在os的目录dest和source上有文件生成,开始初始化流复制环境。
结束后检查副库的DBA_APPLY,DBA_CAPTURE,DBA_PROPGATION是否状态正常。
如果要启用实时复制还需要添加副库的standby redo
alter database add standby logfile '/u01/app/oradata/test/stdbyredo01.log' size 50m;
alter database add standby logfile '/u01/app/oradata/test/stdbyredo02.log' size 50m;
alter database add standby logfile '/u01/app/oradata/test/stdbyredo03.log' size 50m;
alter database add standby logfile '/u01/app/oradata/test/stdbyredo04.log' size 50m;
并修改
BEGIN
DBMS_CAPTURE_ADM.SET_PARAMETER(
capture_name => 'CAPTURE_SKY',
parameter => 'downstream_real_time_mine',
value => 'y');
END;
/
然后在主库端切换一下redo就可以看到副库alert中显示开始挖掘standby redo了。目前实施复制问题比较多,在10.0.2.3上经常出现无故apply abort的情况,需要stop 3个进程:
exec dbms_apply_adm.stop_apply('apply_sky');
exec dbms_propagation_adm.stop_propagation('prop_sky');
exec DBMS_CAPTURE_ADM.STOP_CAPTURE('capture_sky');
再重新start,然后在主库alter system archive log current;才会继续同步
如果发现数据迟迟不同步可以检查v$buffer_queue中的spill,如果spill很大表示捕获了但是没有apply。
在卸载环境时,exec dbms_streams_adm.remove_streams_configuration最好先去dest上执行,不然可能会报错ORA-24042,导致清理环境情况变复杂。
执行后drop复制的schema,重启db,不然v$buffer_queue会残留信息。同样的,如果做db级的流复制:
begin
DBMS_STREAMS_ADM.MAINTAIN_GLOBAL(
source_directory_object => 'DIR_SOURCE',
destination_directory_object => 'DIR_DEST',
source_database => 'primary.com',
destination_database => 'stream.com',
perform_actions => true,
dump_file_name => 'streams_rep.dmp',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_FULL_NETWORK);
end;
/
如果发现问题重做,必须把复制的主要用户连都删除,否则会出现很多意外错误.
如果要作多用户的复制,必须借助DBMS_UTILITY.UNCL_ARRAY
DECLARE
us DBMS_UTILITY.UNCL_ARRAY;
BEGIN
US(1):='MSG';
US(2):='ol';
US(3):='music';
US(4):='FRIEND';
US(5):='collect';
US(6):='blog';
US(7):='ask';
US(8):='cms';
US(9):='ALBUM';
US(10):='MANAGE';
US(11):='shop';
US(12):='cm';
US(13):='GROUPTEAM';
US(14):='JYGH';
US(15):='NEWAP';
US(16):='PK';
US(17):='API';
US(18):='video';
DBMS_STREAMS_ADM.MAINTAIN_SCHEMAS(
schema_names => us,
source_directory_object => 'DIR_SOURCE',
destination_directory_object => 'DIR_DEST',
source_database => 'PRIMARY.COM',
destination_database => 'STREAM.COM',
perform_actions => true,
dump_file_name => 'menhu.dmp',
capture_queue_table => 'rep_capture_queue_table',
capture_queue_name => 'rep_capture_queue',
capture_queue_user => NULL,
apply_queue_table => 'rep_dest_queue_table',
apply_queue_name => 'rep_dest_queue',
apply_queue_user => NULL,
capture_name => 'capture_menhu',
propagation_name => 'prop_menhu',
apply_name => 'apply_menhu',
log_file => 'export_sky.clg',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_SCHEMA_NETWORK);
END;
/
另外如果发生APPLY异常aborted的情况,可以观察DBA_APPLY中的ERROR_MESSAGE,比如发现下面的信息:
ORA-26714: User error encountered while applying
这时候再去检查dba_apply_error可以发现:
ORA-01422: exact fetch returns more than requested number of rows
这类错误最好的解决方法就是每张复制的表都生成主键。然后就是针对情况进行解决了,还是要多看alert和trc文件才能找到原因
另外发现一个downstream real-time apply的最大的bug,restart 副库后,副库就不再同步,查询V$STREAMS_CAPTURE,capture就停止在PAUSED FOR FLOW CONTROL上,其它的进程都是enable的,只能重新初始化复制环境。所以local stream捕捉相对来说还是比较稳定的,速度上也不错,事务量不大的时候几乎做到了实时复制。
另外还有个要命的bug,删除环境后,queue不能删除
使用stadm查询:
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
REP_CAPTURE_QUEUE_TABLE TABLE
AQ$_REP_CAPTURE_QUEUE_TABLE_S TABLE
AQ$_REP_CAPTURE_QUEUE_TABLE_T TABLE
AQ$REP_CAPTURE_QUEUE_TABLE_S VIEW
AQ$_REP_CAPTURE_QUEUE_TABLE_H TABLE
SYS_IOT_OVER_52389 TABLE
AQ$_REP_CAPTURE_QUEUE_TABLE_G TABLE
AQ$_REP_CAPTURE_QUEUE_TABLE_I TABLE
。。。。。。。
需要使用:
exec DBMS_AQADM.DROP_QUEUE_TABLE('REP_CAPTURE_QUEUE_TABLE',true);
exec DBMS_AQADM.DROP_QUEUE_TABLE('REP_DEST_QUEUE_TABLE',true);
来drop对应的queue table。
总的来说,local stream相对稳定,downstream 的real-time apply看上去很美。。。。但是因为在10gR2中刚刚推出,bug多得足以让任何DBA胆寒 - -
维护local stream需要注意,如果要添加新的复制站点,capture_queue_table和apply_queue_table以及queue的名字一定不能重复,否则出错后使用dbms_streams_adm.recover_operation会造成之前的站点因为queue被禁用而停止复制,同时主库会报:
ORA-25207: enqueue failed, queue STADM.REP_CAPTURE_QUEUE is disabled from enqueueing
如果在复制schema的环境中需要添加新的schema,只需要重复运行:
BEGIN
DBMS_STREAMS_ADM.MAINTAIN_SCHEMAS(
schema_names => 'SKY',
source_directory_object => 'DIR_SOURCE',
destination_directory_object => 'DIR_DEST',
source_database => 'JIAOYOU.COM',
destination_database => 'TEST.COM',
perform_actions => true,
dump_file_name => 'SKY.dmp',
capture_queue_table => 'rep_capture_queue_table',
capture_queue_name => 'rep_capture_queue',
capture_queue_user => NULL,
apply_queue_table => 'rep_dest_queue_table',
apply_queue_name => 'rep_dest_queue',
apply_queue_user => NULL,
capture_name => 'capture_sky',
propagation_name => 'prop_sky',
apply_name => 'apply_sky',
log_file => 'export_sky.clg',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_SCHEMA_NETWORK);
END;
/
就可以了,queue和table都是可以reuse的
Dynamic Streams views
Streams View Name Streams View Name from any RAC instance
V$STREAMS_CAPTURE GV$STREAMS_CAPTURE
V$STREAMS_APPLY_COORDINATOR GV$STREAMS_APPLY_COORDINATOR
V$STREAMS_APPLY_READER GV$STREAMS_APPLY_READER
V$STREAMS_APPLY_SERVER GV$STREAMS_APPLY_SERVER
V$STREAMS_POOL_ADVICE GV$STREAMS_POOL_ADVICE
V$STREAMS_TRANSACTION GV$STREAMS_TRANSACTION
V$BUFFERED_PUBLISHERS GV$BUFFERED_PUBLISHERS
V$BUFFERED_QUEUES GV$BUFFERED_QUEUES
V$BUFFERED_SUBSCRIBERS GV$BUFFERED_SUBSCRIBERS
V$PROPAGATION_RECEIVER GV$PROPAGATION_RECEIVER
V$PROPAGATION_SENDER GV$PROPAGATION_SENDER
V$RULE GV$RULE
V$RULE_SET GV$RULE_SET
V$RULE_SET_AGGREGATE_STATS GV$RULE_SET_AGGREGATE_STATS
Static Streams Views
Capture Views
---------------
DBA_CAPTURE
DBA_CAPTURE_EXTRA_ATTRIBUTES
DBA_CAPTURE_PARAMETERS
DBA_CAPTURE_PREPARED_DATABASE
DBA_CAPTURE_PREPARED_SCHEMAS
DBA_CAPTURE_PREPARED_TABLES
Apply Views
--------------
DBA_APPLY
DBA_APPLY_CONFLICT_COLUMNS
DBA_APPLY_DML_HANDLERS
DBA_APPLY_ENQUEUE
DBA_APPLY_ERROR
DBA_APPLY_EXECUTE
DBA_APPLY_INSTANTIATED_GLOBAL
DBA_APPLY_INSTANTIATED_OBJECTS
DBA_APPLY_INSTANTIATED_SCHEMAS
DBA_APPLY_KEY_COLUMNS
DBA_APPLY_OBJECT_DEPENDENCIES
DBA_APPLY_PARAMETERS
DBA_APPLY_PROGRESS
DBA_APPLY_SPILL_TXN
DBA_APPLY_TABLE_COLUMNS
DBA_APPLY_VALUE_DEPENDENCIES
Propagation & Queue Views Streams Views
-------------------------------------------
DBA_PROPAGATION
DBA_QUEUE_SCHEDULES
DBA_QUEUE_SUBSCRIBERS
DBA_QUEUE_TABLES
DBA_QUEUES
推荐几个有帮助的metalink文档:
335516.1 Streams Performance Recommendations
437838.1 Recommended Patch for Streams
290605.1 Oracle Streams STRMMON Monitoring Utility
392809.1 11g Streams New Features
418755.1 10.2.0.x.x Streams Recommendations
273674.1 Streams Configuration Report and Health Check Script
230898.1 How To Troubleshoot the Streams Apply Process
421183.1 How To Enable Capture, Propagation, Apply Tracing
729860.1 Troubleshooting Queries in Streams
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/79686/viewspace-1009920/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/79686/viewspace-1009920/