Skip to content

Instantly share code, notes, and snippets.

@jpirir
Last active December 9, 2020 21:34
Show Gist options
  • Save jpirir/e71adedfbc20b01b90b6e38b94bb1cf4 to your computer and use it in GitHub Desktop.
Save jpirir/e71adedfbc20b01b90b6e38b94bb1cf4 to your computer and use it in GitHub Desktop.
Identify blocked objects and users related, based at http://sushantadba.blogspot.com/2016/05/find-current-and-historical-blocking.html
select distinct
b.username user_
,d.username blocked_by_user_
,t1.time_
,t1.sql_text
,t1.*
from (
SELECT distinct a.sql_id, a.blocking_session,a.blocking_session_serial# blocking_session_serial,
to_char(a.sample_time,'hh24:mi:ss') time_,
a.user_id, s.sql_text,a.module
FROM V$ACTIVE_SESSION_HISTORY a, v$sql s
where a.sql_id=s.sql_id
and blocking_session is not null
--and a.user_id <> 0
and a.sample_time between to_date('09/12/2020 00:00', 'dd/mm/yyyy hh24:mi') and to_date('09/12/2020 23:59', 'dd/mm/yyyy hh24:mi')
)t1
left join ALL_USERS b on (t1.user_id = b.user_id)
left join V$ACTIVE_SESSION_HISTORY c on (t1.blocking_session = c.session_id and t1.blocking_session_serial= c.session_serial#)
left join ALL_USERS d on (c.user_id = d.user_id)
order by 3 desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment