Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle query execution time

I would like to get the query execution time in Oracle. I don't want the time Oracle needs to print the results - just the execution time.

In MySQL it is easy to get the execution time from the shell.

How can I do this in SQL*Plus?

like image 847
user429743 Avatar asked Aug 24 '10 17:08

user429743


People also ask

How do you find the time taken to execute a query in Oracle?

Answer: For seeing the elapsed time for an individual query, you can see individual query response time in SQL*Plus with the "set timing on" command. For DBA's, Oracle has several tools for measuring system-wide response time using v$sysmetric, v$active_session_history, v$sqlarea and v$sysmetric_summary.

How do you find the expected time of completion of an Oracle query?

We can use the information in the v$session_longops view to determine the working time and the remaining time of a transaction in an active session. It is also possible to have information about the related session.

Why does Oracle query take so long to execute?

On a large table this could take a long time either way, maybe even longer than the 4 or 5 minutes you're seeing. Once the data is retrieved, the temporary index would be dropped in the background. When you do another query, Oracle needs to build a new temporary index, which is why it takes that long for every query.


2 Answers

One can issue the SQL*Plus command SET TIMING ON to get wall-clock times, but one can't take, for example, fetch time out of that trivially.

The AUTOTRACE setting, when used as SET AUTOTRACE TRACEONLY will suppress output, but still perform all of the work to satisfy the query and send the results back to SQL*Plus, which will suppress it.

Lastly, one can trace the SQL*Plus session, and manually calculate the time spent waiting on events which are client waits, such as "SQL*Net message to client", "SQL*Net message from client".

like image 147
Adam Musch Avatar answered Sep 19 '22 15:09

Adam Musch


Use:

set serveroutput on variable n number exec :n := dbms_utility.get_time; select ...... exec dbms_output.put_line( (dbms_utility.get_time-:n)/100) || ' seconds....' ); 

Or possibly:

SET TIMING ON;  -- do stuff  SET TIMING OFF; 

...to get the hundredths of seconds that elapsed.

In either case, time elapsed can be impacted by server load/etc.

Reference:

  • ASKTOM - SET TIMING ON/OFF
like image 38
OMG Ponies Avatar answered Sep 19 '22 15:09

OMG Ponies