This post describe the SQL to fetch "Top 5 Fore-Ground Wait Events" from history of Oracle database which can be used to analyze the performance of database while a defined time interval.
Script:
SELECT b.begin_snap,(b.begin_snap+1) end_snap,b.inst_number,b.event,ROUND(b.WAIT_TIME_Sec,1) WAIT_TIME_Sec
FROM
(SELECT a.begin_snap,a.inst_number,a.event,a.DIFF WAIT_TIME_Sec,
row_number () over (partition BY a.begin_snap,a.inst_number order by a.DIFF DESC ) AS ROWNUMBERING
FROM (SELECT e.snap_id begin_snap,e.instance_number inst_number,e.event_name event,
(e.TIME_WAITED_MICRO_FG/1000000) Time_Wait_Sec,
lead((TIME_WAITED_MICRO_FG/1000000)) over (order by e.event_name,e.instance_number,e.snap_id) Next_Time_wait_Sec,
greatest (0, ((lead((TIME_WAITED_MICRO_FG/1000000)) over (order by e.event_name,e.instance_number,e.snap_id))-(e.TIME_WAITED_MICRO_FG/1000000))) DIFF
FROM dba_hist_system_event e
WHERE snap_id > trunc(sysdate)-1
--and sn.begin_interval_time BETWEEN to_date('10-JUL-16 00:00','DD-MON-YY HH24:MI') AND to_date('28-JUL-16 00:00','DD-MON-YY HH24:MI')
AND e.event_name NOT LIKE ('%SQL*Net%')
AND e.event_name NOT LIKE ('%jobq slave wait%')
AND e.event_name NOT IN ('gc cr request')
ORDER BY e.snap_id,
e.instance_number,
e.event_name
) a
WHERE a.DIFF >0
ORDER BY a.begin_snap,
a.inst_number,
a.DIFF,
a.event
)b
WHERE rownumbering <= 5
ORDER BY b.begin_snap,
b.inst_number,
b.rownumbering;
Script:
SELECT b.begin_snap,(b.begin_snap+1) end_snap,b.inst_number,b.event,ROUND(b.WAIT_TIME_Sec,1) WAIT_TIME_Sec
FROM
(SELECT a.begin_snap,a.inst_number,a.event,a.DIFF WAIT_TIME_Sec,
row_number () over (partition BY a.begin_snap,a.inst_number order by a.DIFF DESC ) AS ROWNUMBERING
FROM (SELECT e.snap_id begin_snap,e.instance_number inst_number,e.event_name event,
(e.TIME_WAITED_MICRO_FG/1000000) Time_Wait_Sec,
lead((TIME_WAITED_MICRO_FG/1000000)) over (order by e.event_name,e.instance_number,e.snap_id) Next_Time_wait_Sec,
greatest (0, ((lead((TIME_WAITED_MICRO_FG/1000000)) over (order by e.event_name,e.instance_number,e.snap_id))-(e.TIME_WAITED_MICRO_FG/1000000))) DIFF
FROM dba_hist_system_event e
WHERE snap_id > trunc(sysdate)-1
--and sn.begin_interval_time BETWEEN to_date('10-JUL-16 00:00','DD-MON-YY HH24:MI') AND to_date('28-JUL-16 00:00','DD-MON-YY HH24:MI')
AND e.event_name NOT LIKE ('%SQL*Net%')
AND e.event_name NOT LIKE ('%jobq slave wait%')
AND e.event_name NOT IN ('gc cr request')
ORDER BY e.snap_id,
e.instance_number,
e.event_name
) a
WHERE a.DIFF >0
ORDER BY a.begin_snap,
a.inst_number,
a.DIFF,
a.event
)b
WHERE rownumbering <= 5
ORDER BY b.begin_snap,
b.inst_number,
b.rownumbering;
No comments:
Post a Comment