undo Segment深入解析(二)

2014-11-24 17:17:56 · 作者: · 浏览: 1
_UNDORETENTION is given in seconds.


select to_char(begin_time, 'DD-MON-RR HH24:MI') begin_time,


to_char(end_time, 'DD-MON-RR HH24:MI') end_time, tuned_undoretention


from v$undostat order by end_time;


BEGIN_TIME END_TIME TUNED_UNDORETENTION


--------------- --------------- -------------------


04-FEB-05 00:01 04-FEB-05 00:11 12100


...


07-FEB-05 23:21 07-FEB-05 23:31 86700


07-FEB-05 23:31 07-FEB-05 23:41 86700


07-FEB-05 23:41 07-FEB-05 23:51 86700


07-FEB-05 23:51 07-FEB-05 23:52 86700


576 rows selected.


回滚段自动管理模式下UNDO block分配算法


1、如果当前extent有空闲的数据块,则使用当前extent


2、如果当前extent的下一个extent已经处于过期(expired)状态,那么环绕(wrap)到一个extent,然后使用该extent的第一个数据块。


3、如果下一个extent没有expired,则从undo tablespace中分配空间。如果有剩余空间则使用新分配extent的第一个数据块。此时undo tablespace的使用率开始增加。


4、如果没有剩余空闲的extent,则从offline状态的回滚段中偷取(steal)过期的extent,加入当前回滚段,并使用第一个数据块。


5、如果offline状态的回滚段中没有expired extent,则从online状态的回滚段中偷取(steal)过期区加入到当前的回滚段中,并使用extent中的第一个数据块。


6、如果undo tablespace可以扩展,则扩展undo tablespace,并将新extent加入到当前的回滚段中,同时使用第一个数据块,此时undo所占的操作系统空间开始增加。


7、如果undo tablespace 不能扩展,则自动调整(下降幅度为10%)回滚段的保留时间,然后偷取在更短保留时间下的未过期的extent,如果还未找到过期的extent,则继续以10%的速度减少回滚段的保留时间,重复几次。


8、随机从其他offline状态的回滚段中偷取未过期(unexpired)的extent。


9、尝试使用当前回滚段中未过期的extent,如果所有的区都为ACTIVE状态,则进入下一步。


10、如果以上所有的尝试都失败,则报ORA-30036的错误。


[oracle@rh6 ~]$ oerr ora 30036


30036, 00000, "unable to extend segment by %s in undo tablespace '%s'"


// *Cause: the specified undo tablespace has no more space available.


// *Action: Add more space to the undo tablespace before retrying


// the operation. An alternative is to wait until active


// transactions to commit.


案例


10:34:45 SYS@ prod>select tablespace_name,contents from dba_tablespaces;


TABLESPACE_NAME CONTENTS


------------------------------ ---------


SYSTEM PERMANENT


SYSAUX PERMANENT


TEMP TEMPORARY


USERS PERMANENT


UNDOTBS2 UNDO


EXAMPLE PERMANENT


TBS1 PERMANENT



7 rows selected.



Elapsed: 00:00:00.03


10:34:56 SYS@ prod>create undo tablespace undotbs1


10:35:15 2 datafile '/u01/app/oracle/oradata/prod/undotbs1.dbf' size 1m;



Tablespace created.



Elapsed: 00:00:01.38


10:35:40 SYS@ prod>show parameter undo



NAME TYPE VALUE


------------------------------------ ----------- ------------------------------


undo_management string AUTO


undo_retention integer 900


undo_tablespace string UNDOTBS2



10:35:49 SYS@ prod>alter system set undo_tablespace=undotbs1;



System altered.


Elapsed: 00:00:00.13


10:36:03 SYS@ prod>


10:36:03 SYS@ prod>select s.sid,s.serial#,s.username,u.segment_name,count(u.extent_id) "Extent count",


10:37:37 2 t.used_ublk,t.used_urec,s.program


10:38:00 3 from v$session s,v$transaction t,dba_undo_extents u


10:38:24 4 where s.taddr=t.addr and u.segment_name like '_SYSSMU'||t.xidusn||'_%$' and u.status='ACTIVE'


10:39:50 5 GROUP BY s.sid,s.serial#,s.username,u.segment_name,t.used_ublk,t.used_urec,s.program


10:40:37 6 order by t.used_ublk desc,t.used_urec desc,s.sid,s.serial#,s.username,s.program;



开启新的session,执行DML:



10:41:45 SYS@ prod>conn scott/tiger


Connected.


10:42:45 SCOTT@ prod>insert into t1 select * from t1 where rownum <1000;



99