先看官方解释:
[oracle@centos6 scripts]$ 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产生原因通常有两种:
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 undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
SQL> 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 immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 751595520 bytes
Fixed Size 2257032 bytes
Variable Size 490737528 bytes
Database Buffers 255852544 bytes
Redo Buffers 2748416 bytes
Database mounted.
Database opened.4. 打开对实验表查询的游标
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
828450
SQL> var x refcursor
SQL> 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 x
ERROR:
ORA-01555: snapshot too old: rollback segment number 11 with name
"_SYSSMU11_113091394$" too small
no rows selected避免ORA-01555的方法
1. 增大Undo表空间,增大undo_retention的参数设置
2. 优化应用,减少select语句消耗的时间,能快速执行
3. 从事务上考虑,减少DML操作
博客介绍了ORA-01555错误的官方解释,包括由于长时间运行的SQL、Undo表空间不足、大量事务和频繁提交等原因导致的一致性读问题。通过模拟场景,提出增大Undo表空间、调整undo_retention参数和优化SQL执行等避免方法。

892

被折叠的 条评论
为什么被折叠?



