oracle 之 Undo Retention

oralce database 根据undo表空间大小和系统活动状态自动调整保留时间,可以调整undo_retention 参数设置保留时间。但是准确的将分为如下两种情况。
1)在国定大小的undo表空间中undo_retention参数被忽略,oracle会根据系统活动和空间大小自动调整合适的保留时间来满足应用需求。如果决定把undo 表空间设置为固定大小,那么一定要保证该空间具有足够的size。该undo_retention设置的参数被忽略,如果 选择的空间很小那么会出现如下情况
1、dml会失败,因为没有足够的空间去分配新的事务。
2、运行很长的query可能会出现snapshot too old 错误 ,这是由于不能满足一致性读的问题 (常见为 ORA-01555)

eg:

1)创建一个很小的不是自动扩展的表空间

SQL> create undo tablespace undotbs3 datafile '/opt/app/oracle/RHYS/undotbs3.dbf' size 50M autoextend off;

Tablespace created.

SQL> select file_name,tablespace_name,autoextensible from dba_data_files;

FILE_NAME                                          TABLESPACE_NAME                AUT
-------------------------------------------------- ------------------------------ ---
/opt/app/oracle/RHYS/system01.dbf                  SYSTEM                         YES
/opt/app/oracle/RHYS/sysaux01.dbf                  SYSAUX                         YES
/opt/app/oracle/RHYS/undotbs01.dbf                 UNDOTBS1                       YES
/opt/app/oracle/RHYS/users01.dbf                   USERS                          YES
/opt/app/oracle/RHYS/test.dbf                      TEST                           YES
/opt/app/oracle/RHYS/arch_tbs01.dbf                ARCH_TBS                       NO
/opt/app/oracle/RHYS/statspack.dbf                 STATSPACK                      NO
/opt/app/oracle/RHYS/undotbs2.dbf                  UNDOTBS2                       YES
/opt/app/oracle/RHYS/undotbs21.dbf                 UNDOTBS2                       NO
/opt/app/oracle/RHYS/undotbs3.dbf                  UNDOTBS3                       NO

10 rows selected.

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_optimizer_undo_cost_change          string      11.2.0.1
undo_management                      string      AUTO
undo_retention                       integer     60
undo_tablespace                      string      UNDOTBS2
SQL> alter system set undo_tablespace=undotbs3;

System altered.

SQL> select a.name,a.usn,b.status from v$rollstat b,v$rollname a where a.usn=b.usn;

NAME                                  USN STATUS
------------------------------ ---------- ---------------
SYSTEM                                  0 ONLINE
_SYSSMU21_285059280$                   21 ONLINE
_SYSSMU22_1963502844$                  22 ONLINE
_SYSSMU23_2778616806$                  23 ONLINE
_SYSSMU24_564050484$                   24 ONLINE
_SYSSMU25_800148274$                   25 ONLINE
_SYSSMU26_1460554600$                  26 ONLINE
_SYSSMU27_931264876$                   27 ONLINE
_SYSSMU28_1920348465$                  28 ONLINE
_SYSSMU29_1181389426$                  29 ONLINE
_SYSSMU30_2665996069$                  30 ONLINE

11 rows selected.

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_optimizer_undo_cost_change          string      11.2.0.1
undo_management                      string      AUTO
undo_retention                       integer     60
undo_tablespace                      string      UNDOTBS3
SQL>

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_optimizer_undo_cost_change          string      11.2.0.1
undo_management                      string      AUTO
undo_retention                       integer     60
undo_tablespace                      string      UNDOTBS3
SQL> select begin_time,end_time,undotsn,undoblks,maxquerylen,maxqueryid from v$undostat;

BEGIN_TIM END_TIME     UNDOTSN   UNDOBLKS MAXQUERYLEN MAXQUERYID
--------- --------- ---------- ---------- ----------- -------------
21-AUG-13 21-AUG-13          9         18         336 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         41         940 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8          6         338 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         60         939 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         12         337 0rc4km05kgzb9

SQL> r                       
  1* select begin_time,end_time,undotsn,undoblks,maxquerylen,maxqueryid from v$undostat

BEGIN_TIM END_TIME     UNDOTSN   UNDOBLKS MAXQUERYLEN MAXQUERYID
--------- --------- ---------- ---------- ----------- -------------
21-AUG-13 21-AUG-13          9          0         336 0rc4km05kgzb9
21-AUG-13 21-AUG-13          9         18         336 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         41         940 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8          6         338 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         60         939 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         12         337 0rc4km05kgzb9

6 rows selected.

2)看到系统自动调整的undo retention为940s

SQL> delete from t;

73083 rows deleted.

SQL> begin              
  2  for i in 1..100 loop
  3  insert into t select * from obj$;
  4  commit;
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> r
  1  begin
  2  for i in 1..100 loop
  3  insert into t select * from obj$;
  4  commit;
  5  end loop;
  6* end;

PL/SQL procedure successfully completed.

SQL> select count(*) from t;

COUNT(*)
----------
  14624600

SQL> select begin_time,end_time,undotsn,undoblks,maxquerylen,maxqueryid from v$undostat;

BEGIN_TIM END_TIME     UNDOTSN   UNDOBLKS MAXQUERYLEN MAXQUERYID
--------- --------- ---------- ---------- ----------- -------------
21-AUG-13 21-AUG-13          9       8554         637 0rc4km05kgzb9
21-AUG-13 21-AUG-13          9         18         336 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         41         940 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8          6         338 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         60         939 0rc4km05kgzb9
21-AUG-13 21-AUG-13          8         12         337 0rc4km05kgzb9

6 rows selected.

SQL> show parameter undo_retention

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_retention                       integer     60
SQL> select file_name,tablespace_name,bytes/1024/1024||'M' MB,autoextensible from dba_data_files;

FILE_NAME                                          TABLESPACE_NAME                MB                                        AUT
-------------------------------------------------- ------------------------------ ----------------------------------------- ---
/opt/app/oracle/RHYS/system01.dbf                  SYSTEM                         990M                                      YES
/opt/app/oracle/RHYS/sysaux01.dbf                  SYSAUX                         600M                                      YES
/opt/app/oracle/RHYS/undotbs01.dbf                 UNDOTBS1                       325M                                      YES
/opt/app/oracle/RHYS/users01.dbf                   USERS                          5M                                        YES
/opt/app/oracle/RHYS/test.dbf                      TEST                           1480M                                     YES
/opt/app/oracle/RHYS/arch_tbs01.dbf                ARCH_TBS                       500M                                      NO
/opt/app/oracle/RHYS/statspack.dbf                 STATSPACK                      200M                                      NO
/opt/app/oracle/RHYS/undotbs2.dbf                  UNDOTBS2                       376.9375M                                 YES
/opt/app/oracle/RHYS/undotbs21.dbf                 UNDOTBS2                       50M                                       NO
/opt/app/oracle/RHYS/undotbs3.dbf                  UNDOTBS3                       50M                                       NO

10 rows selected.

3)删除一个大表,产生数据前镜像需要使用undo

SQL> delete from t;
delete from t
            *
ERROR at line 1:
ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDOTBS3'

可以看到已经无法分配空间了,导致了dml错误。

注意:自动调整保留时间对于lobs不适应,lobs依然使用undo_retention进行保留。
2)当undo tablespace为 自动扩展的话,那么可以 通过 设置undo_retention参数进行保留一定的undo record单位为妙,如果没有达到该值,那么会自动扩展表空间,当达到maxsize那么就会overwrite record。但是可以使用guarantee参数,强制不覆盖undo记录。但是这是 会出现error提示。另外oracle自动调整保留策略是max((undo_retention),(maxquery+300))。

oracle该自动调整retention 受一个隐含参数控制,当该隐含参数为false,那么该自动调整功能失效,受undo_retention参数影响。

eg:

  • SQL> get getpar.sql
      1* select a.ksppinm,b.ksppstvl,a.ksppdesc from x$ksppcv b,x$ksppi a where a.indx=b.indx and a.ksppinm like '%&var%'
    SQL> set linesize 200
    SQL> set verify off
    SQL> r
      1* select a.ksppinm,b.ksppstvl,a.ksppdesc from x$ksppcv b,x$ksppi a where a.indx=b.indx and a.ksppinm like '%&var%'
    Enter value for var: undo_autotune

    KSPPINM                        KSPPSTVL                                 KSPPDESC
    ------------------------------ ---------------------------------------- ----------------------------------------
    _undo_autotune                 TRUE                                     enable auto tuning of undo_retention

    SQL>

  • Reference:

  • The UNDO_RETENTION parameter is ignored for a fixed size undo tablespace. The database always tunes the undo retention period for the best possible retention, based on system activity and undo tablespace size. See "Automatic Tuning of Undo Retention" for more information.

  • For an undo tablespace with the AUTOEXTEND option enabled, the database attempts to honor the minimum retention period specified by UNDO_RETENTION. When space is low, instead of overwriting unexpired undo information, the tablespace auto-extends. If the MAXSIZE clause is specified for an auto-extending undo tablespace, when the maximum size is reached, the database may begin to overwrite unexpired undo information. The UNDOTBS1 tablespace that is automatically created by DBCA is auto-extending.

  • Oracle Database automatically tunes the undo retention period based on how the undo tablespace is configured.

    If the undo tablespace is configured with the AUTOEXTEND option, the database dynamically tunes the undo retention period to be somewhat longer than the longest-running active query on the system. However, this retention period may be insufficient to accommodate Oracle Flashback operations. Oracle Flashback operations resulting in snapshot too old errors are the indicator that you must intervene to ensure that sufficient undo data is retained to support these operations. To better accommodate Oracle Flashback features, you can either set the UNDO_RETENTION parameter to a value equal to the longest expected Oracle Flashback operation, or you can change the undo tablespace to fixed size.

  • If the undo tablespace is fixed size, the database dynamically tunes the undo retention period for the best possible retention for that tablespace size and the current system load. This best possible retention time is typically significantly greater than the duration of the longest-running active query.

    If you decide to change the undo tablespace to fixed-size, you must choose a tablespace size that is sufficiently large. If you choose an undo tablespace size that is too small, the following two errors could occur:

    • DML could fail because there is not enough space to accommodate undo for new transactions.

    • Long-running queries could fail with a snapshot too old error, which means that there was insufficient undo data for read consistency.

  • note:

  • Automatic tuning of undo retention is not supported for LOBs. This is because undo information for LOBs is stored in the segment itself and not in the undo tablespace. For LOBs, the database attempts to honor the minimum undo retention period specified by UNDO_RETENTION. However, if space becomes low, unexpired LOB undo information may be overwritten.

oracle 之 Undo Retention相关推荐

  1. oracle 10g undo 管理,Oracle 10g undo表空间管理

    一.oracle 9i起,有两种undo管理方式:AUM Automatic Undo ManagementMUN Manual Undo Management建议使用 AUM ,下面只讨论AUM 一 ...

  2. oracle 10g磁盘管理,Oracle 10g UNDO表空间过大导致磁盘空间不足的解决

    在Oracle 10g数据库的应用中,出现了UNDO表空间过大导致磁盘空间不足而崩溃的现象(ORA-30036: unable to extend segment by 8 in undo table ...

  3. [Oracle]理解undo表空间

    [Oracle]理解undo表空间 一.回退段介绍 在Oracle数据库中,当某个事物对数据进行修改时,Oracle首先将数据的原始值保存到一个回退段中.一个事物只能将它的回退信息保存到一个回退段中, ...

  4. 【Oracle】undo 自动调优

      Oracle 10gr2的后续版本中添加了UNDO信息最短保留时间段自动调优的特性,不再仅仅依据参数UNDO_RETENTION的设定,其调优原则如下: 1 当UNDO TABLESPACE为 f ...

  5. oracle undo head,淺談Oracle的undo管理

    1.什么是undo 當我們對數據執行修改操作時,數據庫會生成undo 信息,這樣一旦執行的事務或語句由於某種原因失敗,或者發出一條ROLLBACK 語句請求回滾,就可以利用這些undo信息將數據放回到 ...

  6. oracle 12c undo,Oracle 12c 新特性之临时Undo--temp_undo_enabled

    Oracle 12c 新特性之临时Undo--temp_undo_enabled 每个 Oracle 数据库包含一组与系统相关的表空间,例如 SYSTEM , SYSAUX , UNDO&TE ...

  7. oracle更换undo,ORACLE UNDO

    undo 是用来回滚的,而且oracle 的undo有undo segment 在数据文件的目录下有UNDO.LOG 有这么一个物理的文件 还有undo实际上只是逻辑上的undo,也就是说:undo是 ...

  8. Oracle redo/undo 原理理解

    Oracle redo/undo 原理理解 undefined 参考:https://www.iteye.com/blog/liwenshui322-1488949 https://blog.csdn ...

  9. Oracle——redo+undo总结

    <Oracle------redo> 重做日志文件(redo log file)对数据库来说至关重要,他们是数据库的事务日志: Oracle数据库维护着两类重做日志文件:在线重做日志文件( ...

最新文章

  1. Android深度探索HAL与驱动开发—第8章
  2. 如何使用 sklearn 优雅地进行数据挖掘?
  3. linux桌面服务器系统下载,Ubuntu 14.10 中文桌面版/服务器正式版下载
  4. MYSQL重置ROOT密码
  5. How to convert hair particles to mesh in Blender
  6. 基于74系列芯片的红绿灯设计
  7. 三款适合HDMI信号分配的分配器芯片
  8. 函数求和代码 matlab,一个简单求和函数的matlab实现(带程序耗时功能)
  9. 【gitee】解决gitee本地提交但是无法显示贡献度(绿点)的问题
  10. 其实带宽≠速度 ADSL加速法完全功略
  11. 《设计模式》笔记 02 - 实例研究:设计一个文档编辑器
  12. 高等数学Mathematica实验题——费马素数猜想(Fn=2^(2^n)+1为素数)的证伪(Verification of Fermat's Prime Number Function)
  13. 转:用调制解调器打电话收传真-ModemFax
  14. [C语言]常用库函数
  15. 【转】浅谈程序猿的职业规划,看你如何决定自己的未来吧。
  16. 安装design compiler的教程
  17. 华为2288HV5服务器内存插法及内存插槽位置
  18. java继承和接口的优缺点_Java抽象类和接口的优缺点---总结-2
  19. 熊掌号周级推送php教程,浅析,熊掌号:实时、小时、天级、周级收录!
  20. 如何策划新闻稿,低成本实现品牌影响力增长

热门文章

  1. 【Java】算法积累1——大整数相加
  2. android手机上的返回键和home键
  3. 网易云音乐接入微信状态
  4. 职场必备:Excel2016,官方推荐使用技巧
  5. python-matplotlib库绘制饼形图专题(从一般饼状图到内嵌环形图)
  6. 利用Python实现模糊查找
  7. NVIDIA 显卡驱动CUDA ToolkitcuDNN下载地址
  8. javascript 正则里面 \s\S 和 . 的区别
  9. 免安装版tomcat 开机自启动设置
  10. 单点登录系统中如何共享cookie