retention guarantee使用场景和作用

发布时间 2023-07-21 15:16:52作者: Allen158

retention guarantee使用场景和作用

undo_retention参数的作用:
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并自动退出。 在Oracle10g中如何要修改guarantee模式可以。

查询表空间是否guarantee
SQL> select tablespace_name,block_size,extent_management , segment_space_management,contents,retention from dba_tablespaces;
使undo表空间retention guarantee
SQL>alter tablespace undo_samll retention guarantee; 表空间已更改。
SQL> select tablespace_name,block_size,extent_management segment_space_management,contents,retention from dba_tablespaces;
需要注意的是这种guarantee模式只针对undo tablespace别的表空间是不适用的。
在Oracle 10g中我们还可以设置undo_retention=0来让Oracle自动调整保留提交后undo信息的时间。

10g 中RETENTION GUARANTEE 的作用
1、先解释下undo_retention
设置undo_retention,保证commit 后的数据在undo segment中保留多长时间。但是并不能保证commit后的undo 信息在undo_retention的时间内一定不被覆写,当undo segment不够时,还是会覆盖已commit的undo 信息。
2、如果需要保证在undo_retention时间内undo 信息一定不被覆写的话,可以对undo segment设置RETENTION GUARANTEE。但是这个参数受到undo_retention和undo size的限制。如果undo size 太小,undo_retention设置太久,设置retention guarantee 时就会报错:
ORA-30036: unable to extend segment by 8 in undo tablespace ‘UNDOTBS2’
3、设置该参数
alter tablespace undotbs2 retention guarantee;
撤销该参数
alter tablespace undotbs2 retention noguarantee;