tags:

views:

149

answers:

3

Any idea about ORA-1555: snapshot too old: rollback segment number I am getting this error and nothing seems to be wrong. Please state under what conditions in may occur and how it can be avoided?

+2  A: 

I suggest you read Tom's answer : http://asktom.oracle.com/pls/asktom/f?p=100:11%3A0%3A%3A%3A%3AP11%5FQUESTION%5FID:1441804355350

"The ORA-1555 happens when people try to save space typically. They'll have small rollback segments that could grow if they needed (and will shrink using OPTIMAL). So, they'll start with say 10 or so 1meg rollback segments. These rollback segments COULD grow to 100meg each if we let them (in this example) however, they will NEVER grow unless you get a big transaction.
"

guigui42
Yes I have a big transaction
Sachin Chourasiya
THe link is very useful but I need some more info
Sachin Chourasiya
Again, i m only quoting the link :"What you need to do here is size rollback so that it wraps less frequently (less frequently then your long running queries)"You need more info, but we also need more info from what you are trying to do, and when does it occurs ...
guigui42
+1  A: 

Typically this occurs when code commits inside a cursor.

eg.

for x in (select ... from ...)
loop
   do something
   commit;
end loop;

See the AskTom link form guigui42 though for other examples.

David Aldridge
How to avoid it
Sachin Chourasiya
Commit at the end only. Commiting does not free up resources in oracle in the same way as it does in some other systems because a lock is very lughtweight, and readers and writers do not block each other. Commits more frequently than needed is a common design error when working with Oracle.
David Aldridge
Better still, don't use a cursor of course.
David Aldridge
Or you can try the controlled commit. Commit for every 100th row or more.
Guru
It's still inefficient. Why would you commit at all before your transaction was complete?
David Aldridge
+1  A: 

Frequent commits can be the cause of ORA-1555. It's all about read consistency. The time you start a query oracle records a before image. So the result of your query is not altered by DML that takes place in the mean time (your big transaction). The before image uses the rollback segments to get the values of data that is changed after the before image is taken. By committing in your big transaction you tell oracle the rollback data of that transaction can be overwritten. If your query need data from the rollback segments that is overwritten you get this error. The less you commit the less chance you have that the rollback data you need is overwritten.

One common cause of ORA-1555 is a procedure that does this all in itself : a cursor on a table, loop through the records, and updates/delete the same table and commits every x records.

As guigui told : let the rollback segments grow to contain your whole transaction

Robert Merkwürdigeliebe