我们先看看对于UNDO_RETENTIOIN的解释:
10G的解释:
UNDO_RETENTION
specifies (in seconds) the low threshold value of undo retention. For AUTOEXTEND undo tablespaces, the system retains undo for at least the time specified in this parameter, and automatically tunes the undo retention period to satisfy the undo requirements of the queries. For fixed- size undo tablespaces, the system automatically tunes for the maximum possible undo retention period, based on undo tablespace size and usage history, and ignores UNDO_RETENTION
unless retention guarantee is enabled.
The UNDO_RETENTION
parameter can only be honored if the current undo tablespace has enough space. If an active transaction requires undo space and the undo tablespace does not have available space, then the system starts reusing unexpired undo space. This action can potentially cause some queries to fail with a "snapshot too old" message.
UNDO_RETENTION参数指定了undo空间保留时间的最低阈值。对于自动扩展的undo表空间,系统至少会保存这个参数指定的undo空间,会自动调整undo的保存时间来满足一些对undo有要求的查询。对于固定大小的undo表空间,会忽略UNDO_RETENTION参数的设置,系统会根据undo表空间的大小和使用的历史情况,去自动调整到undo保存的最大时间,除非 undo表空间设置了retention guarantee。
只有当undo表空间有足够的空间时,UNDO_RETENTION指定的undo保留时间才能被保证。如果一个正在执行的事务需要undo空间,但是undo表空间又没有这么大的可用空间时,系统就会重用未过期的undo空间。这样的操作就可能会引起查询出现快照过旧的问题。
通过上面10G,11G对UNDO_RETENTION的解释,我们可以解释一些现象:
1. 为什么DBA_UNDO_EXTENTS里老是有那么多EXPIRED的区不回收?--因为oracle在空间足够的情况下,只保证UNDO_RETENTIOIN参数指定的最小保留时间,至于最长保留多久就是它自己管理的,我们管不着。
2. 如果保证undo的保留时间?alter tablespace UNDOTBS1 retention guarantee;alter tablespace UNDOTBS1 retention noguarantee;
3. undo空间的使用顺序是什么?
如果空间足够的情况下(包括能够自动扩展):使用多余的空间(包括过期的undo空间);
如果过期的undo空间也用完,则看undo表空间guarantee的设置(看dba_tablespace),如果有保障,则不会用未过期的undo空间(操作很可能就会失败),如果没有保障则使用未过期的undo空间