SQL Execution Runtime Measure [message #609977] |
Fri, 14 March 2014 17:54 |
ind9
Messages: 65 Registered: January 2009
|
Member |
|
|
Hi All,
I am trying to find out how long a SQL statement is executed and on which time.
While doing so I have used below query
--Top CPU Consuming SQL During A Certain Time Period
SELECT *
FROM
(SELECT a.SQL_ID,
SUM(a.CPU_TIME_DELTA /1000000) CPU_TIME_SECS,
ROUND(SUM(a.CPU_TIME_DELTA/1000000)/60,2) CPU_TIME_Mins,
SUM(a.DISK_READS_DELTA), --Delta number of disk reads for this child cursor
COUNT(a.SQL_ID),
Min (s.BEGIN_INTERVAL_TIME),
Max(s.END_INTERVAL_TIME),
Sq.SQL_TEXT
FROM DBA_HIST_SQLSTAT a,
dba_hist_snapshot s,
V$SQLAREA Sq
WHERE s.snap_id = a.snap_id
AND sq.SQL_ID = a.SQL_ID
--and s.begin_interval_time > sysdate -1
AND a.SNAP_ID BETWEEN 4061 AND 4068
--and EXTRACT(HOUR FROM S.END_INTERVAL_TIME) between 9 and 11
GROUP BY a.SQL_ID,
Sq.SQL_TEXT
ORDER BY CPU_TIME_SECS DESC
)
WHERE rownum <= 1
Output:
SQL_ID CPU_TIME_SECS CPU_TIME_MINS COUNT(A.SQL_ID) MIN(S.BEGIN_INTERVAL_TIME) MAX(S.END_INTERVAL_TIME)
------------- ------------- ------------- --------------- --------------------------- ---------------------------
9wf6xgh5y557p 2072,87889 34,55 5 14.03.14 01:00:27,817000000 14.03.14 06:00:34,599000000
And using the SQL_ID from the above query output,I have queried against ASH V$ACTVIE_SESSION_HISTORY and getting 227 Mins. I couldn't able to understand this output.
From the above output I have got the CPU TIME as 34 Mins but from the below query getting it as 227 Mins.
Select Min(ash.sample_Time), Max (Sample_Time), Round (Count (*)/60, 2) Mins
From V$ACTIVE_SESSION_HISTORY ash
Where ash.SQL_ID = '9wf6xgh5y557p'
--and ash.SNAP_ID BETWEEN 4062 AND 4068
and ash.sample_time >= to_date('14-03-2014 00:46:01','dd-mm-yyyy hh24:mi:ss') --sample_time = '08.03.14 18:06:34,335000000'
and ash.sample_time <= to_date('14-03-2014 07:35:01','dd-mm-yyyy hh24:mi:ss') --sample_time = '12.03.14 13:48:50,138000000'--
--Order By ash.sample_Time
;
MIN(ASH.SAMPLE_TIME) MAX(SAMPLE_TIME) MINS
--------------------------- --------------------------- ----------
14.03.14 01:17:57,468000000 14.03.14 05:31:21,880000000 227,02
Is it that the program executing with the above SQL ID is spending 227 Mins to execute only this statement?
Could anone help me to understand this results and kindly help me to correct myself?
Thanks & Regards,
Ind.
|
|
|
Re: SQL Execution Runtime Measure [message #609991 is a reply to message #609977] |
Sat, 15 March 2014 02:25 |
John Watson
Messages: 8960 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
I do not think your queries are comparable.
The DBA_HIST_% views query the AWR, which is populated from AWR snapshots. There is no reason why a snapshot should contain every SQL that was executed in the time frame. The V$ views should contain every SQL, but their time frame is not fixed.
I am of course open to correction on this, but I think you need to write queries after specifying what you want to discover. Can you explain the requirement more precisely?
--
update: actually, it is worse than that. Your second query hits v$active_session_history, which is a sampled view (unlike v$sqlarea) but as the sampling is every second, there is no reason for any correlation with the DBA_HIST_% views which are (by default) populated from hourly samples.
[Updated on: Sat, 15 March 2014 03:27] Report message to a moderator
|
|
|
Re: SQL Execution Runtime Measure [message #609992 is a reply to message #609991] |
Sat, 15 March 2014 03:33 |
ind9
Messages: 65 Registered: January 2009
|
Member |
|
|
Dear John,
Thank you for your reply. On our productive system there is a time PLSQL package function which ran for approximately 6 hrs:30 mins between the time frame 14.03.14 00:00:27 and 14.03.14 06:30:34.
This PLSQL Package function consists the SQL statement with ID "9wf6xgh5y557p".
Now I am trying to find out when this statement execution began and ended and how long it has been executed.
Thanks in advance!
|
|
|
|