===================================================
Overview
~~~~~~~~
This article will discuss the circumstances under which a query can return the O
racle
error ORA-01555 "snapshot too old (rollback segment too small)". The article wil
l then
proceed to discuss actions that can be taken to avoid the error and finally will
provide
some simple PL/SQL scripts that illustrate the issues discussed.
Terminology
~~~~~~~~~~~
It is assumed that the reader is familiar with standard Oracle terminology such
as
'rollback segment' and 'SCN'. If not, the reader should first read the Oracle Se
rver
Concepts manual and related Oracle documentation.
In addition to this, two key concepts are briefly covered below which help in th
e
understanding of ORA-01555:
1. READ CONSISTENCY:
====================
This is documented in the Oracle Server Concepts manual and so will not be discu
ssed
further. However, for the purposes of this article this should be read and under
stood if
not understood already.
Oracle Server has the ability to have multi-version read consistency which is in
valuable
to you because it guarantees that you are seeing a consistent view of the data (
no 'dirty
reads').
ORA-01555 Explanation
~~~~~~~~~~~~~~~~~~~~~
There are two fundamental causes of the error ORA-01555 that are a result of Ora
cle
trying to attain a 'read consistent' image. These are :
o The rollback information itself is overwritten so that Oracle is unable to r
ollback
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 transa
ction
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 que
ry is
first started and to which Oracle is trying to attain a read consistent image. A
ssociated
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 OVERWRITTEN
This breaks down into two cases: another session overwriting the rollback that
the
current session requires or the case where the current session overwrites the r
ollback
information that it requires. The latter is discussed in this article because th
is is
usually the harder one to understand.
Steps:
1. Session 1 starts query at time T1 and QENV 50
2. Session 1 selects block B1 during this query
3. Session 1 updates the block at SCN 51
4. 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 o
f the
block as of this QENV.
If an old enough version of the block can be found in the buffer cache th
en we
will use this, otherwise we need to rollback the current block to generate anoth
er
version of the block as at the required QENV.
It is under this condition that Oracle may not be able to get the require
d
rollback information because Session 1's changes have generated rollback informa
tion that
has overwritten it and returns the ORA-1555 error.
CASE 2 - ROLLBACK TRANSACTION SLOT OVERWRITTEN
1. Session 1 starts query at time T1 and QENV 50
2. Session 1 selects block B1 during this query
3. Session 1 updates the block at SCN 51
4. 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 transactio
n table
such that it eventually wraps around (the slots are written to in a circular fas
hion) and
overwrites all the slots. Note that Oracle is free to reuse these slots since al
l
transactions are committed.
6. Session 1's query then visits a block that has been changed since the ini
tial QENV
was established. Oracle therefore needs to derive an image of the block as at th
at 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 ove
rwritten
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 da
ta block.