`

ORA-01555 原因与解决

 
阅读更多
ORA-01555的解释

假设有张表,叫table1,里面有5000万行数据,假设预计全表扫描1次需要1个小时,我们从过程来看:

1、在1点钟,有个用户A发出了select * from table1;此时不管将来table1怎么变化,正确的结果应该是用户A会看到在1点钟这个时刻table1的内容。这个是没有疑问的。
2、在1点30分,有个用户B执行了update命令,更新了table1表中的第4000万行的这条记录,这时,用户A的全表扫描还没有到达第4000 万条。毫无疑问,这个时候,第4000万行的这条记录是被写到了回滚段里去了的,我假设是回滚段RBS1,如果用户A的全表扫描到达了第4000万行,是 应该会正确的从回滚段RBS1中读取出1点钟时刻的内容的。(未更新前的数据)
3、这时,用户B将他刚才做的操作commit了,但是这时,系统仍然可以给用户A提供正确的数据,因为那第4000万行记录的内容仍然还在回滚段 RBS1里,系统可以根据SCN来到回滚段里找到正确的数据,但是大家注意到,这时记录在RBS1里的第4000万行记录已经发生了一点重大的改变:就是 这个第4000万行的在回滚段RBS1里的数据有可能随时被覆盖掉,因为这条记录已经被提交了!
4、由于用户A的查询时间漫长,而业务在一直不断的进行,RBS1回滚段在被多个不同的tracnsaction使用着,这个回滚段里的extent循环到了第4000万行数据所在的extent,由于这条记录已经被标记提交了,所以这个extent是可以被其他transaction覆盖掉的!
5、到了1点40分,用户A的查询终于到了第4000万行,而这时已经出现了第4条说的情况,需要到回滚段RBS1去找数据,但是已经被覆盖掉了,于是01555就出现了。

 

ORA-01555 Explanation
There are two fundamental causes of the error ORA-01555 that are a result of Oracle trying to attain a ‘read consistent‘ image. These are :o The rollback information itself is overwritten so that Oracle is unable to rollback the (committed) transaction entries to attain a sufficiently old enough version of the block.o The transaction slot in the rollback segment‘s transaction table (stored in the rollback segment‘s header) is overwritten, and Oracle cannot rollback the transaction header sufficiently to derive the original rollback segment transaction slot.Both of these situations are discussed below with the series of steps that cause the ORA-01555. In the steps, reference is made to ‘QENV‘. ‘QENV‘ is short for ‘Query Environment‘, which can be thought of as the environment that existed when a query is first started and to which Oracle is trying to attain a read consistent image. Associated with this environment is the SCN (System Change Number) at that time and hence, QENV 50 is the query environment with SCN 50.CASE 1 - ROLLBACK OVERWRITTENThis breaks down into two cases: another session overwriting the rollback that the current session requires or the case where the current sessionoverwrites the rollback information that it requires. The latter is discussed in this article because this is usually the harder one to understand.Steps:1. Session 1 starts query at time T1 and QENV 502. Session 1 selects block B1 during this query3. Session 1 updates the block at SCN 514. Session 1 does some other work that generates rollback information.5. Session 1 commits the changes made in steps ‘3‘ and ‘4‘.
(Now other transactions are free to overwrite this rollback information)6. Session 1 revisits the same block B1 (perhaps for a different row).Now, Oracle can see from the block‘s header that it has been changed and it is later than the required QENV (which was 50). Therefore we need to get an image of the block as of this QENV.If an old enough version of the block can be found in the buffer cache then we will use this, otherwise we need to rollback the current block to generate another version of the block as at the required QENV.It is under this condition that Oracle may not be able to get the required rollback information because Session 1‘s changes have generated rollback information that has overwritten it and returns the ORA-1555 error.CASE 2 - ROLLBACK TRANSACTION SLOT OVERWRITTEN1. Session 1 starts query at time T1 and QENV 502. Session 1 selects block B1 during this query3. Session 1 updates the block at SCN 514. Session 1 commits the changes
(Now other transactions are free to overwrite this rollback information)5. A session (Session 1, another session or a number of other sessions) then use the same rollback segment for a series of committed transactions.These transactions each consume a slot in the rollback segment transaction table such that it eventually wraps around (the slots are written to in a circular fashion) and overwrites all the slots. Note that Oracle is free to reuse these slots since all transactions are committed.6. Session 1‘s query then visits a block that has been changed since the initial QENV was established. Oracle therefore needs to derive(获得) an image of the block as at that point in time.Next Oracle attempts to lookup the rollback segment header‘s transaction slot pointed to by the top of the data block. It then realises that this has been overwritten and attempts to rollback the changes made to the rollback segment header to get the original transaction slot entry.If it cannot rollback the rollback segment transaction table sufficiently it will return ORA-1555 since Oracle can no longer derive the required version of the data block.It is also possible to encounter a variant of the transaction slot being overwritten when using block cleanout. This is briefly described below :Session 1 starts a query at QENV 50. After this another process updates the blocks that Session 1 will require. When Session 1 encounters these blocks it determines that the blocks have changed and have not yet been cleaned out (via delayed block cleanout). Session 1 must determine whetherthe rows in the block existed at QENV 50, were subsequently changed,In order to do this, Oracle must look at the relevant rollback segment transaction table slot to determine the committed SCN. If this SCN is after the QENV then Oracle must try to construct an older version of the block and if it is before then the block just needs clean out to be good enough forthe QENV.If the transaction(处理) slot has been overwritten and the transaction table cannot be rolled back to a sufficiently old enough version then Oracle cannot derive the block image and will return ORA-1555.(Note: Normally Oracle can use an algorithm for determining a block‘s SCN during block cleanout even when the rollback segment slot has been overwritten.But in this case Oracle cannot guarantee that the version of the block has not changed since the start of the query).
 
解决问题的办法
 
This section lists some of the solutions that can be used to avoid(避免)the ORA-01555 problems discussed in this article. It addresses the cases where rollback segment information is overwritten by the same session and when the rollback segment transaction table entry is overwritten.It is worth highlighting(最重要的) that if a single session experiences the ORA-01555 and it is not one of the special cases listed at the end of this article, then the session must be using an Oracle extension延伸 whereby由此 fetches across commits are tolerated. This does not follow the ANSI model and in the rare cases where ORA-01555 is returned one of the solutions below must be used.CASE 1 - ROLLBACK OVERWRITTEN1.Increase size of rollback segment which will reduce the likelihood of overwriting rollback information that is needed.2.Reduce the number of commits (same reason as 1).3.Run the processing against a range of data rather than the whole table.
(Same reason as 1).4.Add additional(附加) rollback segments. This will allow the updates etc. to be spread across more rollback segments thereby reducing the chances of overwriting required rollback information.5.If fetching across commits, the code can be changed so that this is not done.6.Ensure that the outer select does not revisit the same block at different times during the processing. This can be achieved by :- Using a full table scan rather than an index lookup
- Introducing a dummy sort so that we retrieve all the data, sort it and then sequentially visit these data blocks.CASE 2 - ROLLBACK TRANSACTION SLOT OVERWRITTEN1. Use any of the methods outlined above except for ‘6‘. This will allow transactions to spread their work across multiple rollback segments therefore reducing the likelihood or rollback segment transaction table slots being consumed.2. If it is suspected that the block cleanout variant is the cause, then force block cleanout to occur prior to the transaction that returns the ORA-1555. This can be achieved by issuing the following in SQL*Plus, SQL*DBA or Server Manager :alter session set optimizer_goal = rule;
select count(*) from table_name;If indexes are being accessed then the problem may be an index block and clean out can be forced by ensuring that all the index is traversed. Eg, if the index is on a numeric column with a minimum value of 25 then the following query will force cleanout of the index :select index_column from table_name where index_column > 24;Examples
~~~~~~~~
Listed below are some PL/SQL examples that can be used to illustrate the ORA-1555 cases given above. Before these PL/SQL examples will return this error the database must be configured as follows :o Use a small buffer cache (db_block_buffers).REASON: You do not want the session executing the script to be able to find old versions of the block in the buffer cache which can be used to satisfy a block visit without requiring the rollback information.o Use one rollback segment other than SYSTEM.REASON: You need to ensure that the work being done is generating rollback information that will overwrite the rollback information required.o Ensure that the rollback segment is small.REASON: See the reason for using one rollback segment.ROLLBACK OVERWRITTENrem * 1555_a.sql -
rem * Example of getting ora-1555 "Snapshot too old" by
rem * session overwriting the rollback information required
rem * by the same session.drop table bigemp;
create table bigemp (a number, b varchar2(30), done char(1));drop table dummy1;
create table dummy1 (a varchar2(200));rem * Populate the example tables.
begin
for i in 1..4000 loop
insert into bigemp values (mod(i,20), to_char(i), ‘N‘);
if mod(i,100) = 0 then
insert into dummy1 values (‘ssssssssssss‘);
commit;
end if;
end loop;
commit;
end;
/rem * Ensure that table is ‘cleaned out‘.
select count(*) from bigemp;declare
-- Must use a predicate so that we revisit a changed block at a different
-- time.-- If another tx is updating the table then we may not need the predicate
cursor c1 is select rowid, bigemp.* from bigemp where a < 20;begin
for c1rec in c1 loopupdate dummy1 set a = ‘aaaaaaaa‘;
update dummy1 set a = ‘bbbbbbbb‘;
update dummy1 set a = ‘cccccccc‘;
update bigemp set done=‘Y‘ where c1rec.rowid = rowid;
commit;
end loop;
end;
/ROLLBACK TRANSACTION SLOT OVERWRITTENrem * 1555_b.sql - Example of getting ora-1555 "Snapshot too old" by
rem *overwriting the transaction slot in the rollback
rem *segment header. This just uses one session.drop table bigemp;
create table bigemp (a number, b varchar2(30), done char(1));rem * Populate demo table.
begin
for i in 1..200 loop
insert into bigemp values (mod(i,20), to_char(i), ‘N‘);
if mod(i,100) = 0 then
commit;
end if;
end loop;
commit;
end;
/drop table mydual;
create table mydual (a number);
insert into mydual values (1);
commit;rem * Cleanout demo table.
select count(*) from bigemp;declarecursor c1 is select * from bigemp;begin-- The following update is required to illustrate the problem if block
-- cleanout has been done on ‘bigemp‘. If the cleanout (above) is commented
-- out then the update and commit statements can be commented and the
-- script will fail with ORA-1555 for the block cleanout variant.
update bigemp set b = ‘aaaaa‘;
commit;for c1rec in c1 loop
for i in 1..20 loop
update mydual set a=a;
commit;
end loop;
end loop;
end;
/Special Cases
~~~~~~~~~~~~~
There are other special cases that may result in an ORA-01555. These are given below but are rare and so not discussed in this article :o Trusted Oracle can return this if configured in OS MAC mode. Decreasing LOG_CHECKPOINT_INTERVAL on the secondary database may overcome the problem.o If a query visits a data block that has been changed by using the Oracle discrete transaction facility then it will return ORA-01555.o It is feasible that a rollback segment created with the OPTIMAL clause maycause a query to return ORA-01555 if it has shrunk during the life of the query causing rollback segment information required to generate consistent read versions of blocks to be lost.Summary
~~~~~~~
This article has discussed the reasons behind the error ORA-01555 "Snapshot too old", has provided a list of possible methods to avoid the error when it is encountered, and has provided simple PL/SQL scripts that illustrate the cases discussed.
分享到:
评论

相关推荐

    [Oracle] 浅析令人抓狂的ORA-01555问题

    ORA-01555错误的根本原因是由于Oracle数据库的读一致性机制。在Oracle中,为了保证事务的隔离性,当一个事务试图读取已经被其他事务修改但尚未提交的数据时,系统会从撤销表空间(Undo Tablespace)中查找数据的旧...

    ora 01555 snapshot too old

    ### ORA-01555 "Snapshot too old" — 详细解释与解决方案 #### 概述 在Oracle数据库操作过程中,可能会遇到ORA-01555 "snapshot too old" 错误,该错误主要发生在多版本读一致性环境下,当回滚段中的数据不足以...

    oracle+ora-各种常见java.sq

    - `java.sql.SQLException: ORA-01555: snapshot too old: rollback segment number with name "" too small`: 回滚段不足以支持事务回滚。可能需要增大回滚段大小或者优化事务处理。 11. **内存问题** - `java....

    oracle错误及解决方法

    - **阅读错误信息**:首先,仔细阅读错误提示,它会提供错误的原因和可能的解决方案。 - **查询文档**:Oracle官方文档(如Oracle Database Error Messages)是查找错误解决方案的重要资源,其中详细解释了每个...

    ORA错误分析及解决

    本文将详述如何分析和处理两种特定的ORA错误:ORA-01555和ORA-07445,同时也会探讨与FAST_START_MTTR_TARGET参数相关的四个设置,这些参数对数据库的性能和恢复速度有着直接影响。 首先,让我们深入理解ORA-01555...

    Oracle错误代码及解决方法

    6. ORA-01555:快照过旧。这是因为回滚段空间不足,导致无法读取旧版本的数据。增加回滚段大小、优化事务管理或提升数据库实例的内存配置可缓解此问题。 7. ORA-29913:执行错误。当调用存储过程或函数时,如果参数...

    Oracle 数据库常见问题诊断方法

    ##### 1.5 ORA-01555 - **特征**: - 当前会话无法读取到以前版本的数据。 - **原因**: - 主要原因包括:回滚段太小或数量不足、回滚段冲突、交叉提交等。 - **措施**: - 增加回滚段的数量,以提供更多的空间来...

    oracle 数据库错误一览表

    三、ORA-01555:快照过旧 这个错误表示在事务中尝试回滚到一个不再可用的数据库快照。这可能是因为回滚段空间不足或回滚段被重用。解决方法包括增加回滚段大小,优化事务,或使用更大的undo表空间。 四、ORA-02091...

    Oracle数据库常见问题诊断-常见错误篇

    - **ORA-01041:** 这个错误可能发生在客户端尝试建立与数据库服务器的连接时,由于某种原因(如配置错误)而失败。 **解决办法:** - 检查网络配置文件 `PROTOCOL.ORA` 中是否存在配置错误,特别是 `TCP.NODELAY` ...

    Ora92ErrMsg.zip_oracle

    在"Ora92ErrMsg.chm" 这个帮助文档中,每个错误代码都会详细解释其含义、可能的原因以及如何解决。通过查阅这个文档,我们可以快速理解错误的根源,提高问题诊断和修复的效率。对于日常维护和故障排查,这样的资源是...

    Oracle--errorCode.zip_oracle

    7. **性能优化**:某些错误代码与性能问题相关,比如ORA-01555,通过优化索引、调整表空间或提高redo log大小可能避免这类问题。 8. **最佳实践**:文档可能还会提供避免某些错误的最佳实践,比如正确设计约束、...

    Oracle数据库常见问题诊断方法

    除了上述错误外,文章还提到了其他常见的ORA错误,如ORA-01545、ORA-0165x、ORA-01555、ORA-04031、ORA-04091、ORA-01242和ORA-01113,涵盖了从空间管理、性能瓶颈、到内存不足等各种数据库操作场景中可能遇到的问题...

    ORACLE 错误一览表part6

    在“ORACLEpart6”中,可能包含对这些和其他更多错误的详细解释、可能的原因和解决方法,这对于日常数据库维护和故障排除是非常宝贵的资源。确保理解和应用这些知识,可以提升你的Oracle数据库管理技能,降低系统的...

    ORACLE-ERRORS.zip_oracle

    5. **ORA-01555**: 快照过旧。当试图访问的数据被修改或删除,而回滚段不足以回溯到之前的状态时,会出现这个错误。可能需要增大回滚段大小或优化事务处理。 6. **ORA-12154**: TNS:无法解析指定的连接标识符。这是...

    oracle补丁

    本话题将深入探讨如何解决从Oracle 10g到11g迁移时出现的ORA-39126和ORA-01555错误,并重点关注Oracle补丁“p18082965”的应用。 首先,让我们了解一下这两个错误代码的含义: 1. ORA-39126:这是一个与数据泵相关...

    Oracle错误码大全

    错误码ORA-01555则意味着“快照过旧”,这是由于回滚段空间不足或回滚信息丢失导致的。遇到这种情况,我们需要增大回滚段大小,或者优化事务处理,减少对回滚段的需求。 "Oracle错误码大全"不仅包含了错误码,还...

    OCP 052PDF版本

    综上所述,本文档提供了关于Oracle Database 11g Administration I 中几个常见问题的深入解析,包括ORA-01555错误的原因及处理方法、AWR的工作原理以及如何减少索引碎片等知识点。这些知识点对于理解Oracle数据库的...

    oracle 10g 管理 sql 错误解决

    8. **性能问题**:执行慢的SQL查询可能导致ORA-01555或其他与内存相关的错误。通过分析查询执行计划,优化SQL语句,或调整数据库参数来提升性能。 9. **并发问题**:多个用户同时访问相同资源可能导致锁定和死锁。...

Global site tag (gtag.js) - Google Analytics