Tuesday 3 June 2014

Find Top 100 SQL Statement based on CPU utilization

-----Find Top 100 SQL ID in Oracle----

select * from (select s.sql_id, RANK() OVER (ORDER BY (max(s.CPU_TIME_TOTAL)) DESC) cpu_rank,
RANK() OVER (ORDER BY (max(s.ELAPSED_TIME_TOTAL)) DESC) elapsed_rank
from
   dba_hist_sqlstat s,
   dba_hist_snapshot sn
where
   sn.begin_interval_time between to_date('05-may-2014 0001','dd-mon-yyyy hh24mi')
and
   to_date('12-may-2014 0600','dd-mon-yyyy hh24mi')
and
   sn.snap_id=s.snap_id
group by
   s.sql_id
   ) where cpu_rank <=100 and elapsed_rank<=100;
   






  

-----Find Top 100 SQL text in Oracle----

select sql_id,sql_text from dba_hist_sqltext where sql_id in ( select sql_id from (select s.sql_id, RANK() OVER (ORDER BY (max(s.CPU_TIME_TOTAL)) DESC) cpu_rank,
RANK() OVER (ORDER BY (max(s.ELAPSED_TIME_TOTAL)) DESC) elapsed_rank
from
   dba_hist_sqlstat s,
   dba_hist_snapshot sn
where
   sn.begin_interval_time between to_date('05-may-2014 0001','dd-mon-yyyy hh24mi')
and
   to_date('12-may-2014 0600','dd-mon-yyyy hh24mi')
and
   sn.snap_id=s.snap_id
group by
   s.sql_id
   ) where cpu_rank <=100 and elapsed_rank<=100);

No comments:

Post a Comment