Poitr Sqlid ash event wait check
-- Author: Piotr Sajda
-- The script profiles the waits and cpu time for a given SQL_ID and SQL_EXEC_ID and shows the percentage for each wait event
-- The parameters can be omitted (the script uses the nvl function to accomplish the filtering).
col "avg_wtime[us]" form 999,999
col "min_wtime[us]" form 999,999
col "max_wtime[us]" form 999,999,999,999
compute sum of CNT on report
break on report
select ash.sql_id, nvl(event,'(on CPU)') event,
round(min(ash.time_waited),0) "min_wtime[us]" ,
round(max(ash.time_waited),0) "max_wtime[us]",
round(avg(ash.time_waited),0) "avg_wtime[us]",
count(*) cnt ,
sum(count(*)) over (partition by ash.sql_id) "cnt of all waits for given SQL" ,
round( count(*) / sum(count(*)) over (partition by ash.sql_id) * 100 , 2 ) "% of all waits for sqlid" ,
round( count(*)*100/(sum(count(*)) over ()) , 2) "[ % of all waits ]"
from gv$active_session_history ash
where
ash.sql_id = nvl('&&SQL_ID',ash.sql_id)
-- and to_char(SQL_EXEC_ID) = to_char( nvl('&&SQL_EXEC_ID',ash.SQL_EXEC_ID) )
and sample_time >= ( sysdate - to_number( nvl('&How_Many_Minutes_Back',999999999)/24/60 ) )
and ash.sql_id is not NULL
-- and (event like nvl('&wait_event1',event) OR event like nvl('&wait_event2',event) or event is null)
group by ash.sql_id, event
order by "[ % of all waits ]"
/
Comments
Post a Comment