ORA-30036: unable to extend segment by 8 in undo tablespace "UNDOTBS1"
后进行了下面的一系列的排查分析: 查看undo表空间使用率为100%,查看alert日志中发现了大量的事物已经ORA-01555的报错。 Wed Jan 30 04:32:01 GMT+08:00 2013ORA-01555 caused by SQL statement below (SQL ID: 4ds6qq0mfac2t, Query Duration=5 sec, SCN: 0x0c00.d915c977): Wed Jan 30 04:32:01 GMT+08:00 2013SELECT distinct FILE_NAME,to_char(file_name_time,:"SYS_B_00"),A.operation_type_grade FROM T_FILE_INFO_81 A,T_FILE_CLASS B ,T_FILE_STAT E C WHERE ((A.RAT_FIRST_STARTTIME >=:"SYS_B_01" and A.RAT_FIRST_STARTTIME <=:"SYS_B_02" ) or (A.RAT_LAST_ENDTIME >=:"SYS_B_03" and A.RAT_LAST_ENDTIME <=:"SYS_B_04" ) or (A.RAT_FIRST_STARTTIME <=:"SYS_B_05" and A.RAT_LAST_ENDTIME >= :"SYS_B_06" ) ) and ((A.RAT_FIRST_CALLING_NBR >=:"SYS_B_07" and A.RAT_FIRST_CALLING_NBR <=:"SYS_B_08") or (A.RAT_LAST_CALLING_NBR >= :"SYS_B_09" and A.RAT_LAST_CALLING_NBR <= :"SYS_B_10" ) or (A.RAT_FIRST_CALLING_NBR <=:"SYS_B_11" and A.RAT_LAST_CALLING_NBR >=:"SYS_B_12" )) and A.FILE_NAME <>:"SYS_B_13" and A.File_Class_Id = B.File_Class_Id and B.operati on_type_id=:"SYS_B_14" and (A.FILE_NAME_TIME + interval :"SYS_B_15" day ) > TO_DATE(:"SYS_B_16",:"SYS_B_17") and A.city_id =:"SYS_B_18" and a.state in (:"SYS Wed Jan 30 08:49:12 GMT+08:00 2013insert into STL_GX.T_all_file_TOTAL select aa.province_id, dd.name, aa.BILL_DATE, aa.OPERATION_TYPE_GRADE, :"SYS_B_00", aa.cj_files, bb.pj_files, bb.org_counts, bb.rate_counts, bb.inp_counts, bb.inpc_counts, cc.jf_files, cc.jf_counts, :"SYS_B_01", :"SYS_B_02", aa.is_rate, aa.is_billtag, aa.is_insert, bb.ERR_COUNTS from (SELECT a.province_code as province_id, substr(A.ORG_FILENAME, :"SYS_B_03", :"SYS_B_04") as BILL_DATE, b.operation_type_grade, COUNT(*) as cj_files, b.is_rate as is_rate, b.is_billtag as is_billtag, b.is_insert as is_insert FROM STL_PARA.T_LOG_COLLECT_76@pub_PARA A, stl_gx.tmp_cj_info b WHERE substr(A.ORG_FILENAME, :"SYS_B_05", :"SYS_B_06") = :"SYS_B_07" and b.province_id = :"S Wed Jan 30 09:44:56 GMT+08:00 2013Thread 1 advanced to log sequence 149384 (LGWR switch) Current log# 6 seq# 149384 mem# 0: /dev/rjs_redolog06 Wed Jan 30 09:50:00 GMT+08:00 2013ORA-01555 caused by SQL statement below (SQL ID: 7t0bjnwxt9ufv, Query Duration=180 sec, SCN: 0x0c00.e294a117): 这个很明显,是因为undo中存在大量的insert操作,导致数据库undo没有commit,由于本库的实际环境,之前做过undo_retention的调整。下面看此设定值。 SQL> show parameter undo
NAME TYPE VALUE ------------------------------------ -------------------------------- ------------------------------ undo_management string AUTO undo_retention integer 0 undo_tablespace string UNDOTBS1
undo_management为auto、retention时间为0让Oracle自动调整保留提交后undo信息的时间。Oracle 10g之前,在自动Undo管理的模式下,我们都知道undo_retention参数的作用是用来控制当transaction被commit之后,undo信息的保留时间。这些undo信息可以用来构造consistent read以及用于一系列的闪回恢复,而且足够的undo信息还可以减少ORA-01555错误的发生,在Oracle 9R1中呢,这个value的默认值是900秒,Oracle 9R2以后这个value提高到了10800秒。即使我们设置了undo_retention这个参数,那么在默认情况下,这是一个noguarantee的限制。也就是说我将undo_retention=10800,那么原本以为在一个transaction commit之后,之前的undo还可以保存10800秒,才可以被别的transaction DML覆盖,孰不知当有其他的transaction DML处理过程中需要undo空间的时候,恰恰这个时候not enough space for undo,也就说我并没有允许undo tablespace自动扩展。由于我们的retention是noguarantee的,所以transaction DML就会忽略这种retention的时间限制直接回绕覆盖我们的undo信息,这种结果下其实在很多情况下是不希望得到的。 Oracle 10g之后,oracle提出了一个特性就是undo的guarantee,可以强制oracle来guarantee的undo信息,也就说如果一个session的transaction DML需要undo空间的时候,即使undo的空间不足,这个session也不会强制覆盖由undo_retention所保护的undo信息,那么这个transaction DML会因为undo空间的不足会而report一个error并自动退出。 SQL> select tablespace_name,block_size,extent_management 2 segment_space_management,contents,retention 3 from dba_tablespaces;
TABLESPACE_NAME BLOCK_SIZE SEGMENT_SP CONTENTS RETENTION ------------------------------ ---------- ---------- --------- ----------- SYSTEM 8192 LOCAL PERMANENT NOT APPLY UNDOTBS1 8192 LOCAL UNDO NOGUARANTEE SYSAUX 8192 LOCAL PERMANENT NOT APPLY TEMP 8192 LOCAL TEMPORARY NOT APPLY USERS 8192 LOCAL PERMANENT NOT APPLY COMMDATA 8192 LOCAL PERMANENT NOT APPLY SETTLEINDEX 8192 LOCAL PERMANENT NOT APPLY SETTLEDATA 8192 LOCAL PERMANENT NOT APPLY STATDATA 8192 LOCAL PERMANENT NOT APPLY STATINDEX 8192 LOCAL PERMANENT NOT APPLY COMMINDEX 8192 LOCAL PERMANENT NOT APPLY
TABLESPACE_NAME BLOCK_SIZE SEGMENT_SP CONTENTS RETENTION ------------------------------ ---------- ---------- --------- ----------- RMAN_TBS 8192 LOCAL PERMANENT NOT APPLY
33 rows selected. 把疑问交给ORACLE工程师了,为什么undo_retention设定了900s未即时生效? 通过查看metalink得知一个bug问题ps:Bug 5387030 - Automatic tuning of undo_retention causes unusual extra space allocation [ID 5387030.8] Product (Component) Oracle Server (Rdbms)
Range of versions believed to be affected Versions >= 10.2.0.1 but BELOW 11.1
Versions confirmed as being affected 10.2.0.3 10.2.0.2 10.2.0.1
Description When undo tablespace is using NON-AUTOEXTEND datafiles, V$UNDOSTAT.TUNED_UNDORETENTION may be calculated too high preventing undo block from being expired and reused. In extreme cases the undo tablespace could be filled to capacity by these unexpired blocks.
An alert may be posted on DBA_ALERT_HISTORY that advises to increase the space when it is not really necessary if this fix is applied. If the user sets their own alert thresholds for undo tablespaces the bug may prevent alerts from being produced.
Workaround alter system set "_smu_debug_mode" = 33554432; This causes the v$undostat.tuned_undoretention to be calculated as the maximum of: maxquerylen secs + 300 undo_retention specified in init.ora
Please note: The above is a summary description only. Actual symptoms can vary. Matching to any symptoms here does not confirm that you are encountering this problem. For questions about this bug please consult Oracle Support. References Bug:5387030 (This link will only work for PUBLISHED bugs) Note:245840.1 Information on the sections in this article 我们的数据库版本为10.2.0.5.0满足其Versions >= 10.2.0.1 but BELOW 11.1的条件。对于固定UNDO 表空间,将会通过表空间的剩余空间来最大限度保留UNDO 信息。如果FIXED UNDO 表空间没有对保留时间作GUARANTEE (alter tablespace xxx retention guarantee; ),则undo_retention 参数将不会起作用。(警告:如果设置UNDO 表空间为retention guarantee ,则未过期的数据不会被复写,如果表空间不够则会导致DML 操作失败或者transation 挂起) oracle 10g有自动Automatic Undo Retention Tuning 这个特性。设置的undo_retention 参数只是一个指导值, ,Oracle 会自动调整Undo ( 会跨过undo_retention 设定的时间) 来保证不会出现Ora-1555 错误. 。通过查询V$UNDOSTAT (该视图记录4 天以内的UNDO 表空间使用情况,超过4 天可以查询DBA_HIST_UNDOSTAT 视图) 的tuned_undoretention (该字段在10G 版本才有,9I 是没有的)字段可以得到Oracle 根据事务量(如果是文件不可扩展,则会考虑剩余空间)采样后的自动计算出最佳的retenton 时间。这样对于一个事务量分布不均匀的 数据库 来说, ,就会引发潜在的问题-- 在批处理的时候可能Undo 会用光, 而且这个状态将一直持续, 不会释放。 如何取消 10g 的 auto UNDO Retention Tuning ,有如下三种方法:
PS:Automatic Tuning of Undo_retention Causes Space Problems [ID 420525.1] : Automatic Tuning of Undo_retention Causes Space Problems1.) Set the autoextend and maxsize attribute of each datafile in the undo ts so it is autoextensible and its maxsize is equal to its current size so the undo tablespace now has the autoextend attribute but does not autoend: SQL> alter database datafile "<datafile_flename>" autoextend on maxsize <current_size>;With this setting, v$undostat.tuned_undoretention is not calculated based on a percentage of the undo tablespace size, instead v$undostat.tuned_undoretention is set to the maximum of (maxquerylen secs + 300) undo_retention specified in init.ora file.2.) Set the following hidden parameter in init.ora file: _smu_debug_mode=33554432orSQL> Alter system set "_smu_debug_mode" = 33554432;With this setting, v$undostat.tuned_undoretention is not calculated based on a percentage of the fixed size undo tablespace, instead v$undostat.tuned_undoretention is set to the maximum of (maxquerylen secs + 300) undo_retention specified in init.ora file.3.) Set the following hidden parameter in init.ora: _undo_autotune = falseorSQL> Alter system set "_undo_autotune" = false; 可动态调整无需重启数据库。 Autotune of undo retention is turned off. Wed Jan 30 20:59:26 GMT+08:00 2013ALTER SYSTEM SET _undo_autotune=FALSE SCOPE=BOTH; SQL> show parameter undo
NAME TYPE VALUE ------------------- ----------------- ---------- _undo_autotune boolean FALSE undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDOTBS1 在设定完_undo_autotune后,并且结果应用方跑存储过程,未发现ORA-30036: unable to extend segment by 8 in undo tablespace "UNDOTBS1"错误(此错误并没有在alert日志中体现。)更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址