Welcome 微信登录

首页 / 数据库 / MySQL / Oracle ORA-01555(快照过旧)

一、引言:[Oracle@www.linuxidc.com]$ oerr ora 01555
01555, 00000, "snapshot too old: rollback segment number %s with name "%s" too small"
// *Cause: rollback records needed by a reader for consistent read are
//     overwritten by other writers
// *Action: If in Automatic Undo Management mode, increase undo_retention
//          setting. Otherwise, use larger rollback segments    ORA-01555 快照过旧,是数据库中很常见的一个错误,比如当我们的事务需要使用undo来构建CR块的时候,而此时对应的undo已经不存在了,这个时候就会报ORA-01555的错误。    ORA-01555错误在Oracle 8i及之前的版本最多。从9i开始的undo自动管理,至现在的10g、11g中的undo auto tuning,使得ORA-01555的错误越来越少。但是这个错误,仍然不可避免。二、出现ORA-01555错误,通常有2中情况:    (1)、SQL语句执行时间太长,或者undo表空间过小,或者事务量过大,或者过于频繁的提交,导致执行SQL过程中进行一致性读时,SQL执行后修改的前镜像(既UNDO数据)在UNDO表空间中已经被覆盖,不能构造一致性读块(CR blocks)。这种情况最多。    (2)、SQL语句执行过程中,访问到的块,在进行延迟块清除时,不能确定该块的事务提交时间与SQL执行开始时间的先后次序。这种情况很少。三、模拟ORA-01555场景:SQL> create table jack (id int,name varchar2(10));Table created.SQL> insert into jack values(1,"a");1 row created.SQL> insert into jack values(2,"b");1 row created.SQL> commit;Commit complete.SQL> show parameter undoNAME                   TYPE     VALUE
-------------------- ----------- --------------
undo_management          string      AUTO
undo_retention         integer   900
undo_tablespace          string      UNDO2
SQL> create undo tablespace undo1 datafile "/u01/app/oracle/oradata/yft/undo01.dbf" size 1m;Tablespace created.SQL> alter system set undo_retention=1;System altered.SQL> var x refcursor
SQL> begin
  2 open :x for select * from jack;
  3  end;
  4  /PL/SQL procedure successfully completed.SQL> begin
  2    for i in 1 .. 20000 loop
  3 update jack set id=id+1;
  4 commit;
  5  end loop;
  6  end;
  7  /PL/SQL procedure successfully completed.SQL> print :x
ERROR:
ORA-01555: snapshot too old: rollback segment number 17 with name
"_SYSSMU17_2039231318$" too small no rows selected四、第1种情况解决的办法:(1)、增加UNDO表空间大小;(2)、增加undo_retention时间,默认只有15分钟;(3)、优化出错的SQL,减少查询的时间,首选方法;(4)、避免频繁的提交。Oracle ORA-01555 快照过旧 说明  http://www.linuxidc.com/Linux/2012-08/66997.htmORA-01078 和 LRM-00109 报错解决方法 http://www.linuxidc.com/Linux/2012-07/66044.htmORA-01555超长的Query Duration时间  http://www.linuxidc.com/Linux/2013-12/93901.htmORA-00471 处理方法笔记 http://www.linuxidc.com/Linux/2013-09/90017.htmORA-00314,redolog 损坏,或丢失处理方法 http://www.linuxidc.com/Linux/2013-09/90646.htmORA-00257 归档日志过大导致无法存储的解决办法 http://www.linuxidc.com/Linux/2013-09/90594.htm更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址