Oracle 查看当前正在运行的sql并kill会话
Posted Demonson
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle 查看当前正在运行的sql并kill会话相关的知识,希望对你有一定的参考价值。
--查询正在执行SQL语句
select vs.sid,vs.serial#,vs.username,vs.machine,vs.logon_time,v.sql_text,cpu_time,v.sql_id,v.sql_fulltext
from v$session vs,v$process vp,v$sql v
where vs.paddr=vp.addr
and vs.sql_hash_value=v.hash_value
order by cpu_time desc
--生成kill会话语句
select distinct 'alter system kill session '''||VS.sid||','||VS.SERIAL#||''';'
from v$session vs,v$process vp,v$sql v
where VS.PADDR=VP.ADDR
and VS.SQL_HASH_VALUE=V.HASH_VALUE
and sql_text like 'select * from t_mail_down_log '
order by cpu_time desc
--查看当前锁状态
SELECT l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
l.os_user_name,
s.machine,
s.terminal,
o.object_name,
s.logon_time
FROM v$locked_object l,
all_objects o,
v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid,s.serial#;
--根据锁生成kill会话语句
SELECT distinct 'alter system kill session '''|| l.session_id||','|| s.serial#||''';'
FROM v$locked_object l,
all_objects o,
v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid ;
ALTER system KILL session '109,31273';
以上是关于Oracle 查看当前正在运行的sql并kill会话的主要内容,如果未能解决你的问题,请参考以下文章