Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01555 snapshot too old (Oracle 11g)
ORA-01555 snapshot too old [message #613717] Fri, 09 May 2014 12:18 Go to next message
Oracle_Walker
Messages: 71
Registered: January 2012
Location: United States
Member

Experts,

One of my oracle batch job is failing with ORA-01555 snapshot too old error. It is a long running job approx. 4-5 hours and scheduled to after 6 PM everyday. It uses two views which in turns joins multiple tables to fetch data.

Root cause
-----------
Recently i have introduced a update and commit statement within a function in a package, then onwards the job is failing with ORA-01555. So i have reverted my changes in the pkb and redeployed(only the pkb, no changes to the view which uses this pkb). But still the job is failing with ORA-01555. I am triaging further to identify the root cause.

Note : If i schedule this job after 12 AM(midnight) it is completing successfully.

Please help me to identify the root cause or steps for triaging this issue. Thanks in advance.
Re: ORA-01555 snapshot too old [message #613718 is a reply to message #613717] Fri, 09 May 2014 12:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

The first root cause of ORA-01555 is commit inside a loop.

Re: ORA-01555 snapshot too old [message #613719 is a reply to message #613718] Fri, 09 May 2014 12:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Please help me to identify the root cause or steps for triaging this issue.
remove or comment out the COMMIT.
Re: ORA-01555 snapshot too old [message #613720 is a reply to message #613719] Fri, 09 May 2014 12:37 Go to previous messageGo to next message
Oracle_Walker
Messages: 71
Registered: January 2012
Location: United States
Member

Michel & BlackSwan,

Yes, you're correct. I have removed the update & commit from the .pkb and redeployed the .pks and .pkb. The view which uses the function is not redeployed.

One more observation, the view is slightly modified so the job is now running for 11-12 hours and failing with ORA-01555. Also few more indexes were added to tables which were used in the view.
Re: ORA-01555 snapshot too old [message #613721 is a reply to message #613720] Fri, 09 May 2014 12:43 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
ORA-01555 consists of two "competing" SQL statements.
1) the long running SELECT which is the victim that throws ORA-01555 error
2) DML occurs against same table in SELECT FROM along with "frequent" COMMIT; which releases the UNDO segments.

The solution is to reduce the DML or eliminate the COMMIT.
Re: ORA-01555 snapshot too old [message #613722 is a reply to message #613720] Fri, 09 May 2014 12:45 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
I cannot advise on your specific problem, but I can share my experience of a similar problem. It was a job that ran for between 18 and 24 hours. We tried setting undo_retention to 90000, but even that didn't stop the 1555s. The error was on the SQL that populates a cursor, then the code looped through the cursor doing row-by-row processing. My first "fix" was to run the query and write the rows to a global temporary table, then base the cursor on that. Problem solved. The better fix was to tune the SQLs in the loop, so that the process ran in only 6 hours. The real fix would have been to re-write the whole thing so that it wouldn't row-by-row processing.
Re: ORA-01555 snapshot too old [message #613724 is a reply to message #613722] Fri, 09 May 2014 12:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

This first fix is one of the classic fixes of ORA-01555 due a cursor loop; another one is to use ORDER BY on the SELECT, both store on the result in temp segments which are private and so are outside undo as soon as the result set is built.
Of course, the second one is better.
And the best fix is to not use PL/SQL and loops. Razz

Re: ORA-01555 snapshot too old [message #613727 is a reply to message #613720] Fri, 09 May 2014 13:24 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
First off, having DML inside a function is just welcoming issues.

Now, since MC, BS and JW have already told you the consequences of commit inside a block. I would like to know what exactly is your business case which you have inside a function. You can always have a plain SQL instead of a function for DML tasks. I would appreciate if you would share it with us.

Deploying a permanent fix is always much better than a workaround Smile
Re: ORA-01555 snapshot too old [message #613729 is a reply to message #613727] Fri, 09 May 2014 13:56 Go to previous messageGo to next message
Oracle_Walker
Messages: 71
Registered: January 2012
Location: United States
Member

Per my understanding, long running SELECT is the root cause for ORA-01555. Below are only changes added to the view,

1)Added few WHEN and ELSE conditions to a COALESCE function in the SELECT query. It has TO_CHAR function added to one of the column too.

2)Added non-unique INDEX to few tables used in the view(May be this could have modified the execution path of the SELECT query in VIEW)
Re: ORA-01555 snapshot too old [message #613730 is a reply to message #613729] Fri, 09 May 2014 14:00 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
May, might, could, would, can, will etc. is understood by people only when we can see the code and the error. Else, it's almost impossible to comment/suggest without a test case. So why don't you post a test case and lets try to fix your issue.
Re: ORA-01555 snapshot too old [message #613732 is a reply to message #613729] Fri, 09 May 2014 14:08 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Per my understanding, long running SELECT is the root cause for ORA-01555.


No, the root is concurrent DML, long running SELECT is just the victim (as BlackSwan already said).
A SELECT can run a month, if nothing change around then there's no chance to get an ORA-01555.

Re: ORA-01555 snapshot too old [message #613827 is a reply to message #613732] Mon, 12 May 2014 15:13 Go to previous messageGo to next message
Oracle_Walker
Messages: 71
Registered: January 2012
Location: United States
Member

Thanks all for your valuable inputs. I was able to resolve this issue by changing the job's date parameters. It was configured records back from 01-JAN-2013 as a cutoff, so it was doing a Full table scan on transactional table, which it should do a Index scan. Now i have modified to fetch from 3 months old records, so it is doing a Index scan on the table and running successfully.
Re: ORA-01555 snapshot too old [message #613834 is a reply to message #613827] Mon, 12 May 2014 16:01 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
While the error may longer be thrown, IMO you did not fix the root cause.

SELECT alone NEVER throws ORA-01555.
DML is required to produce ORA-01555.

If you are happy, then we are happy.
Re: ORA-01555 snapshot too old [message #613850 is a reply to message #613834] Tue, 13 May 2014 00:51 Go to previous message
Oracle_Walker
Messages: 71
Registered: January 2012
Location: United States
Member

Yes, I am happy. Thanks!
Previous Topic: Multi-step query script in Toad
Next Topic: Replace HTML codes with the special characters in CLOB data types.
Goto Forum:
  


Current Time: Thu Apr 25 12:36:09 CDT 2024