--查询阻塞会话,blocking_session列代表该会话阻塞sid列的会话
SELECT /+rule/
S.SQL_ID,
S.SID,
S.BLOCKING_SESSION,
S.SERIAL#,
S.USERNAME,
W.EVENT,
W.SECONDS_IN_WAIT,
W.WAIT_TIME,
S.LAST_CALL_ET,
S.STATUS,
S.CLIENT_INFO,
Q.SQL_TEXT,
Q.HASH_VALUE,
Q.ADDRESS,
'alter system kill session''' || S.SID || ',' || S.SERIAL# ||
''' immediate;'
FROM V$SESSION_WAIT W,V$SESSION S,V$SQL Q
WHERE W.SID = S.SID
AND Q.HASH_VALUE = S.SQL_HASH_VALUE
AND W.EVENT NOT LIKE '%message from client%'
AND S.SID >= 6
ORDER BY LAST_CALL_ET DESC;
--查看阻塞会话的状态是否活动,客户端标识,机器名称,根据这个内容可以判断出NMC线程监控中的sname,bname,tname
select vs.status,vs.CLIENT_IDENTIFIER,vs.MACHINE,vs.sid,vs.SERIAL# from V$SESSION vs where vs.sid='~';
--干掉阻塞会话
alter system kill session '~,~' immediate;
在Oracle数据库中,ALTER SYSTEM KILL SESSION命令用于立即终止指定的会话。~和~表示任何值,所以ALTER SYSTEM KILL SESSION '~', '~' IMMEDIATE;将立即终止任何会话。