Friday, April 30, 2010

find sessions on AWR with given SQL

column start_time format a30
column end_time format a30
column Active_event format 999999
select SESSION_ID,SESSION_SERIAL#,count(*) Active_event ,min(sample_time) Start_time, max(sample_time) End_time,
max(sample_time)-min(sample_time) "Duration(min)"
from dba_hist_active_sess_history
where SQL_ID = &SQL_ID
group by SESSION_ID,SESSION_SERIAL#
order by 6 desc
/

SESSION_ID SESSION_SERIAL# ACTIVE_EVENT START_TIME END_TIME Duration(min)
---------- --------------- ------------ ------------------------------ ------------------------------ -----------------------
2091 1030 549 2010-04-26-22.03.19.111000 2010-04-29-20.02.12.795000 +000000002 21:58:53.684
2094 4777 1210 2010-04-26-22.03.19.111000 2010-04-28-02.48.58.449000 +000000001 04:45:39.338
2100 12331 2747 2010-04-28-18.50.07.503000 2010-04-29-02.32.24.297000 +000000000 07:42:16.794
2094 19156 3 2010-04-22-22.01.18.791000 2010-04-22-22.01.38.991000 +000000000 00:00:20.200
2139 8341 2 2010-04-22-22.01.18.791000 2010-04-22-22.01.28.891000 +000000000 00:00:10.100