–查死锁进程
select c.os_user_name 锁主,to_char(b.sql_exec_start,‘yyyy-mm-dd hh24:mi:ss’) 时间,‘alter system kill session ‘’’||b.sid||’,’||B.serial#||’’’;’ kill语句,a.sql_text 锁命令
from v s q l a j o i n v sql a join v sqlajoinvsession b on a.hash_value=b.sql_hash_value join v$locked_object c on b.sid=c.session_id order by b.sql_exec_start;
select object_name as 对象名称,s.sid,s.serial#,p.spid as 系统进程号,S.sid||’,’||s.Serial# 查杀进程号,l.oracle_username,l.os_user_name
FROM V L O C K E D O B J E C T L , D B A O B J E C T S O , V LOCKED_OBJECT L , DBA_OBJECTS O , V LOCKEDOBJECTL,DBAOBJECTSO,VSESSION S , V$PROCESS P
where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr order by s.sid;
–查询阻塞或死锁的语句
select sql_text from v s q l w h e r e h a s h v a l u e i n ( s e l e c t s q l h a s h v a l u e f r o m v sql where hash_value in (select sql_hash_value from v sqlwherehashvaluein(selectsqlhashvaluefromvsession where sid in
(select session_id from v$locked_object))
–单条解锁
alter system kill session ‘814,938’;
–生成解锁语句
SELECT distinct ‘alter system kill session ‘’’ || l.session_id || ‘,’ || s.serial# || ‘’’;’ yj
FROM V L O C K E D O B J E C T l , V LOCKED_OBJECT l,V LOCKEDOBJECTl,VSESSION S WHERE l.SESSION_ID=S.SID
–批量解锁
DECLARE CURSOR CUR_DETAIL IS select distinct S.sid||’,’||s.Serial#
from v l o c k e d o b j e c t l , d b a o b j e c t s o , v locked_object l , dba_objects o , v lockedobjectl,dbaobjectso,vsession s , v$process p
where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr;
v_id VARCHAR2(50);
v_sql varchar2(50);
BEGIN
OPEN CUR_DETAIL;
LOOP
FETCH CUR_DETAIL INTO v_id ;
exit when CUR_DETAIL%notfound;
BEGIN
v_sql:=‘alter system kill session ‘||’’’’|| v_id ||’’’’;
–dbms_output.put_line(v_sql);
Execute Immediate v_sql;
END;
END LOOP;
close CUR_DETAIL;
end;