Active Session History
Active Session History
Active Session History
numtodsinterval(sum(elapsed_time)/nullif(sum(rows_processed),0),'SECOND')
else
numtodsinterval(sum(elapsed_time/3600)/nullif(sum(rows_processed),0),'HOUR')
end -- Avoid "ORA-01873: the leading precision of the interval is
too small" for large values
as interval day(5) to second(0)) as "Avg time/1M rows"
, sum(px_servers_executions) as "PX server executions"
from ( select s.sql_id
, s.last_active_time
, plan_hash_value
--, executions
, case executions when 0 then 1 else executions end as
executions_calc -- to use in expressions without NULLIF
, px_servers_executions
, elapsed_time
, buffer_gets
, rows_processed
, end_of_fetch_count
from v$sqlstats s )
where sql_id = '&sql_id'
group by trunc(last_active_time), plan_hash_value
having sum(executions_calc) > 0
order by trunc(last_active_time), plan_hash_value;
Session count with granularity every one minute:--
SELECT ss.instance_number,
to_char(force_matching_signature) as force_matching_signature, stat.sql_id,
plan_hash_value, stat.sql_profile,
executions_delta Exe_D, executions_total Exe_T,
round(elapsed_time_delta/1000000,2) Secs_D,
round(elapsed_time_total/1000000,2) Secs_T,
rows_processed_delta Rows_D, rows_processed_total Rows_T,
disk_reads_delta Reads_D, disk_reads_total Reads_T,
ss.begin_interval_time,
ss.end_interval_time, stat.snap_id,
ss.startup_time, flush_elapsed,
parsing_schema_name as parsing_nm,
fetches_delta Fetch_D,
end_of_fetch_count_delta End_Of_Fetch_Cnt_D,
sql_text
FROM DBA_HIST_SNAPSHOT ss, DBA_HIST_SQLSTAT stat, DBA_HIST_SQLTEXT txt
WHERE stat.sql_id = txt.sql_id
AND stat.dbid = txt.dbid
AND ss.dbid = stat.dbid
AND ss.instance_number = stat.instance_number
AND ss.snap_id = stat.snap_id
AND ss.dbid in (select dbid from v$database)
AND ss.instance_number = (select instance_number from gv$instance where
instance_name ='pdw2s1')
and ss.begin_interval_time >= SYSDATE - 30
and upper(sql_text) LIKE '%INSERT /*+ APPEND */ INTO AUTH_CLOG_MATCHING%'
--d txt.sql_id='6v5w592b20kuv'
order by ss.end_interval_time;
----------------------------------------Blocking session
history------------------------------
select
a.sample_time, a.session_id, a.session_state, a.event, a.seq#,
a.time_waited/1000000 time_waited,
a.sql_id, is_sqlid_current, a.sql_opcode, a.blocking_session, current_obj#
from
dba_hist_active_sess_history a
where a.sample_time between to_date('20211026 07:00:00','YYYYMMDD HH24:MI:SS')
and to_date('20211027 07:30:00','YYYYMMDD HH24:MI:SS')
and sql_id = '2whrhbggxn44h'
order by a.sample_time, a.session_id;
SELECT query_runs.*,
ROUND ( (end_time - start_time) * 24, 2) AS duration_hrs
FROM ( SELECT u.username,
ash.program,
ash.sql_id,
ASH.SQL_PLAN_HASH_VALUE as plan_hash_value,
ASH.SESSION_ID as sess#,
ASH.SESSION_SERIAL# as sess_ser,
CAST (MIN (ASH.SAMPLE_TIME) AS DATE) AS start_time,
CAST (MAX (ash.sample_time) AS DATE) AS end_time
FROM dba_hist_active_sess_history ash, dba_users u
WHERE u.user_id = ASH.USER_ID AND ash.sql_id = lower(trim('&sql_id'))
GROUP BY u.username,
ash.program,
ash.sql_id,
ASH.SQL_PLAN_HASH_VALUE,
ASH.SESSION_ID,
ASH.SESSION_SERIAL#) query_runs
ORDER BY sql_id, start_time;