Skip to Main Content
  • Questions
  • How to find time taken by query at each stage while being processed by db

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Rajan.

Asked: June 18, 2018 - 2:42 am UTC

Last updated: June 18, 2018 - 10:14 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hey,
We have some queries that perform too badly during load test. As per DBA the explain looks good.

I want to know if there is a way DBA can monitor the time taken by query at each stage like parsing, executing, returning rows, etc?

Thanks!

and Chris said...

To get this information you need the statement's execution plan. Note execution, NOT explain!

This gives a breakdown of how long each specific step in the plan took. The easiest way is with the SQL monitor, which automatically captures long-running queries. This updates in real time, so you can see how a query progresses as it runs.

But you do need to be licensed for DIAG+TUNING for this!

And quick queries won't appear by default.

You can overcome both of these restrictions by tracing your session. This captures execution details of all SQL within it. If you want to trace an active session, find its sid and serial number and run:

exec DBMS_monitor.session_trace_enable ( <sid>, <serial#>, true, true );


And stop it again by calling:

exec DBMS_monitor.session_trace_disable ( <sid>, <serial#> );


You can then analyze the trace file using TKPROF or other tools.

You can read more about these techniques and more at:

https://blogs.oracle.com/sql/how-to-create-an-execution-plan

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

More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database