Mohamed Houri’s Oracle Notes

February 8, 2007

How to avoid ora-01555 error

Filed under: Ora-01555 — hourim @ 12:14 pm

When dealing with oracle initial loads or with massif updates/deletes that generate undo (also known as rollback) and redo overheads, then the most frequent error in this context is the so famous ORA-01555: Rollback segment snapshot too old.

What also makes this error very frequent in many production applications is the data volume difference between test and production environments of those applications. Due to this data volume difference, the ORA-01555 error takes place most frequently in production were we are too late to change the logic and were it is so difficult to intervene.

This is why one of the obvious but very important solution to avoid this error is to have a real test environment with a leat the same data volume as it will be the case in production. Thus if the ORA-01555 error will have to happen, it will be pointed out much earlier in the development process making changes more flexible.

In On-Line Transaction Processing (OLTP) systems I have been faced with the ORA-01555 error in many cases. One of the main actions I realised I have to do in order to avoid it is to do not commit accross fetch (this is what many developers came to a long time before me).

Commit across fecth represents a commit inside a loop as shown here below:


FOR r_cur IN c_cur LOOP

-- Traitement is done here
 update/delete ....
 COMMIT; -- commit across fetch increases the odds of ora-01555
 END LOOP;

Thus in order to drastically decrease the odds of ORA-01555, commit outside the loop as shown below:


FOR r_cur IN c_cur LOOP
 -- Traitement is done here
 update/delete ....
 END LOOP;
 COMMIT; -- Commit is done here outside the loop

But commiting only once for the whole process will certainly contribute to avoid ORA-01555 error but may also increases the odds of its twin sister ORA-01562 : failed to extend rollback segment number string.

So that the probability of the occurence of both errors will decrease, the above plsql code are updated as follows:

DECLARE
 v_record_number NUMBER := 0;
 v_commit_val NUMBER := 500; -- commit when 500 records have been processed

BEGIN

LOOP -- main technical loop
 v_record_number := 0;

FOR r_cur IN c_cur LOOP

-- log the number of treated record
 v_record_number := v_record_number + 1;

-- Traitement is done here
 update/delete ....

-- Decide to commit
 IF v_record_number >= v_commit_val THEN
 EXIT;
 END IF;

END LOOP;

-- Cursor is closed automatically in the for loop
 COMMIT; -- commit outside the inner loop

EXIT WHEN v_record_number less than v_commit_val ;
 END LOOP; -- inner loop
COMMIT;
 END; -- main technical loop</strong>

In any way, one thing you must absolutely consider is to make your process restartable. If not, then any ORA-01555 or ORA-01562 error will let updates done in the FOR loop cursor in a totally unknown state and will be considered as fatal.

1 Comment »

  1. […] addition to what has been recommended here how to avoid ora-01555 you may also consider this 1. increase size of rollback segment 2  make your query run very […]

    Pingback by Senior Oracle Developer interview I « Oracle, Oracle and Oracle — February 11, 2007 @ 11:41 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Tony's Oracle Tips

Tony Hasler's light hearted approach to learning about Oracle

Richard Foote's Oracle Blog

Focusing Specifically On Oracle Indexes, Database Administration and Some Great Music

Hatem Mahmoud Oracle's blog

Just another Oracle blog : Database topics and techniques

Mohamed Houri’s Oracle Notes

Qui se conçoit bien s’énonce clairement

Oracle Diagnostician

Performance troubleshooting as exact science

Raheel's Blog

Things I have learnt as Oracle DBA

Coskan's Approach to Oracle

What I learned about Oracle

So Many Oracle Manuals, So Little Time

“Books to the ceiling, Books to the sky, My pile of books is a mile high. How I love them! How I need them! I'll have a long beard by the time I read them”—Lobel, Arnold. Whiskers and Rhymes. William Morrow & Co, 1988.

EU Careers info

Your career in the European Union

Carlos Sierra's Tools and Tips

Tools and Tips for Oracle Performance and SQL Tuning

Oracle Scratchpad

Just another Oracle weblog

OraStory

Dominic Brooks on Oracle Performance, Tuning, Data Quality & Sensible Design ... (Now with added Sets Appeal)

%d bloggers like this: