ORA-01555:快照过旧

来源:互联网 发布:cfve软件 编辑:程序博客网 时间:2024/05/16 07:32

先看官方解释:

[oracle@centos6 scripts]$ oerr ora 0155501555, 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
产生原因通常有两种:

1. sql语句执行时间太长,或者Undo表空间过小,或者事务量过大,或者过于频繁的提交,导致执行sql过程中进行一致性读时,sql执行后修改的前镜像(即undo数据)在undo表空间中已经被覆盖,不能构造一致性读块(CR blocks)。为最常见的原因。

2. sql语句执行过程中,访问到的块,在进行延迟块清除时,不能确定该块的事务提交时间与sql执行开始时间的先后次序。这种情况比较少。


模拟ORA-01555场景:

1. 创建测试表,插入数据

SQL> create table gmk(id int,name varchar2(32));Table created.SQL> insert into gmk values(1,'a');1 row created.SQL> insert into gmk values(2,'b');1 row created.SQL> commit;Commit complete.
2. 改变Undo retention的值,默认为900,改为1

SQL> show parameter undoNAME                                 TYPE        VALUE------------------------------------ ----------- ------------------------------undo_management                      string      AUTOundo_retention                       integer     900undo_tablespace                      string      UNDOTBS1SQL> alter system set undo_retention=1;System altered.

3. 创建大小为1m的undo表空间,并切换默认表空间到新建的undo表空间,重启

SQL> create undo tablespace undo1 datafile '/u01/app/oracle/oradata/orcl/undo01.dbf' size 1m;Tablespace created.SQL> alter system set undo_tablespace=undo1 scope=both;System altered.SQL> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SQL> startupORACLE instance started.Total System Global Area  751595520 bytesFixed Size                  2257032 bytesVariable Size             490737528 bytesDatabase Buffers          255852544 bytesRedo Buffers                2748416 bytesDatabase mounted.Database opened.
4. 打开对实验表查询的游标

SQL> select current_scn from v$database;CURRENT_SCN-----------     828450SQL> var x refcursorSQL> begin  2  open :x for select * from gmk;  3  end;  4  /PL/SQL procedure successfully completed.

5. 对表进行频繁的update

SQL> begin  2  for i in 1 .. 20000 loop  3  update gmk set id=id+1;  4  commit;  5  end loop;  6  end;  7  /PL/SQL procedure successfully completed.
6. 打印游标

SQL> print xERROR:ORA-01555: snapshot too old: rollback segment number 11 with name"_SYSSMU11_113091394$" too smallno rows selected

避免ORA-01555的方法

1. 增大Undo表空间,增大undo_retention的参数设置

2. 优化应用,减少select语句消耗的时间,能快速执行

3. 从事务上考虑,减少DML操作




0 0
原创粉丝点击