Skip to Main Content
  • Questions
  • Performance Tuning a PL/SQL procedure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Srikanth.

Asked: June 10, 2016 - 7:07 pm UTC

Last updated: June 13, 2016 - 11:01 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hello,

I have a question on performance tuning. Please help me.

In 1st scenario, I have a procedure which was working fine till yesterday but suddenly it is performing slowly.

In 2nd scenario, the procedure performance is degrading slowly day by day

What are the initial steps I need to take, to overcome these issues?

Thanks in advance!!!!

and Connor said...

In either case, the key is knowing *where* the slow down is occurring. If a PL/SQL procedure consists of a single SQL, then its obvious, but often they have many, or call other procedures etc.

So firstly, run a trace

exec dbms_monitor.session_trace_enable(waits=>true);
exec your_plsql_proc;
exec dbms_monitor.session_trace_disable;

and then run tkprof on the resulting trace file. That now gives you a breakdown of where the time was lost.

The most typical cause for a sudden slow down is normally a poorly running SQL.

For slowly degrading performance, a common cause is looping structures, so on day 1, you loop around something 1 time, 2 times on day 2 etc etc....

But the trace is the key. If the trace does not reveal anything (for example, the plsql code does little or no SQL), then look at the pl/sql profiler to get similar information about the plsql code itself.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, June 13, 2016 - 6:55 am UTC

Hello could you give an example of how using interpreting tkprof ?
Connor McDonald
June 13, 2016 - 11:01 am UTC

Some good info here

http://docs.oracle.com/database/121/TGSQL/tgsql_trace.htm#TGSQL827

But also, the principle is pretty simple - look at the "total" lines for each statement, see which ones take the longest. Then look at the "why" - was it CPU or something else that delayed.

Hope this helps.

Ghassan, June 13, 2016 - 11:07 am UTC

Thank you

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library