V$ACTIVE_SESSION_HISTORY
V$ACTIVE_SESSION_HISTORY
displays sampled session activity in the database.
It contains snapshots of active database sessions taken once a second.
Here are some snippest which I am using.
SELECT TO_CHAR (hs.sample_time, 'hh24:Mi') my_time, hs.*
FROM V$ACTIVE_SESSION_HISTORY hs
WHERE TO_CHAR (hs.sample_time, 'hh24:Mi') LIKE '00:0%'
ORDER BY 2;
SELECT TO_CHAR (hs.sample_time, 'hh24:Mi') my_time, COUNT (*) N
FROM V$ACTIVE_SESSION_HISTORY hs
GROUP BY TO_CHAR (hs.sample_time, 'hh24:Mi')
ORDER BY 1;
for example get the in the most common queries of first three minutes of the day.
SELECT sql_id, COUNT (*)
FROM (
SELECT TO_CHAR (hs.sample_time, 'hh24:Mi') my_time, hs.*
FROM V$ACTIVE_SESSION_HISTORY hs
WHERE TO_CHAR (hs.sample_time, 'hh24:Mi') IN('00:01', '00:02', '00:03')
ORDER BY 2
)
GROUP BY sql_id
ORDER BY COUNT (*) DESC;
SELECT sql_id, module, machine, program, COUNT (*) N
FROM (
SELECT TO_CHAR (hs.sample_time, 'hh24:Mi') my_time, hs.*
FROM V$ACTIVE_SESSION_HISTORY hs
WHERE TO_CHAR (hs.sample_time, 'hh24:Mi') IN ('00:01', '00:02', '00:03')
ORDER BY 2)
GROUP BY sql_id, module, machine, program,
ORDER BY COUNT (*) DESC;
SELECT sql_text
-- sql_fulltext
-- *
FROM v$SQL
WHERE sql_id IN (SELECT ... )