Finding query from oracle which is blocking session

▼魔方 西西 提交于 2020-01-04 05:54:09

问题


I want to find out the query for which any operation is blocked. From DBA I'm getting input that particular session is blocked but I cannot proceed with investigation further without knowing which query is causing issue. is there any way to find out exact query causing issue?


回答1:


First get the SQL_ID of the BLOCKING session from this script:

SELECT /*+ RULE */
s.sid,
s.serial#,
p.spid "OS SID",
s.sql_hash_value "HASH VALUE",
s.username "ORA USER",
s.status,
s.osuser "OS USER",
s.machine,
s.terminal,
s.type,
s.program,
s.logon_time,
s.last_call_et,
s.sql_id,
l.id1,
l.id2,
decode(l.block,0,'WAITING',1,'BLOCKING') block,
decode(
l.LMODE,1,'No Lock',
2,'Row Share',
3,'Row Exclusive',
4,'Share',
5,'Share Row Exclusive',
6,'Exclusive',null) lmode,
decode(
l.REQUEST,1,'No Lock',
2,'Row Share',
3,'Row Exclusive',
4,'Share',
5,'Share Row Exclusive',
6,'Exclusive',null) request ,
round(l.ctime/60,2) "MIN WAITING",
l.type
FROM v$process p, v$session s, v$Lock l
where p.addr = s.paddr
and s.sid=l.sid
and
(l.id1,l.id2,l.type) in
(SELECT l2.id1, l2.id2, l2.type
  FROM V$LOCK l2
  WHERE l2.request<>0)
order by l.id1,l.id2,l.block desc;

Then pass this SQL_ID into this script:

select sql_text from v$sqltext
where sql_id=<SQL_ID>;



回答2:


You can use the following query to find out whichs sessions are bloking and what they do:

select s.module,
       s.program,
       s.machine,
       s.osuser,
       sql.sql_text
from v$session s,
     v$sqlarea sql
where s.sql_id = sql.sql_id
and s.sid in (select blocking_session from v$session)


来源:https://stackoverflow.com/questions/46886403/finding-query-from-oracle-which-is-blocking-session

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!