select b.SID,b.SERIAL#,b.USERNAME,b.STATUS,b.MACHINE,b.LOCKWAIT,b.PROGRAM from V$SESSION b where b.SID in (select a.SESSION_ID from V$LOCKED_OBJECT a);
SID:会话 id
USERNAME:死锁语句所用的数据库用户
STATUS:状态,active 表示死锁
MACHINE:死锁语句所在的机器
LOCKWAIT:死锁的状态,如果有内容表示被死锁
PROGRAM:产生死锁的语句主要来自哪个应用程序
查看锁表执行语句
用sid 查询单个
select a.SQL_TEXT
from V$SQL a
where a.HASH_VALUE in(select b.SQL_HASH_VALUE from V$SESSION b where b.SID ='358');
查询所有加锁的 sql
select a.SQL_TEXT
from V$SQL a
where a.HASH_VALUE in(select b.SQL_HASH_VALUEfrom V$SESSION bwhere b.SID in(select c.SESSION_IDfrom V$LOCKED_OBJECT c));
查询未提交事务的 sql
select s.SID,s.SERIAL#,s.USERNAME,s.LOCKWAIT,s.PROGRAM,s.MACHINE,s.STATUS,TO_CHAR(s.LOGON_TIME,'yyyy-mm-dd hh24:mi:ss') LOGON_TIME,TO_CHAR(t.START_DATE,'yyyy-mm-dd hh24:mi:ss') START_DATE,(select q.SQL_TEXT from V$SQL q where q.LAST_ACTIVE_TIME = t.START_DATE and rownum <=1)assqlfrom V$SESSION s,V$TRANSACTION t
where s.SADDR = t.SES_ADDR
查询锁表的会话 id、及sql 脚本
-- 查询锁表会话ID、sql脚本select s.SID 会话ID,s.SERIAL#,s.USERNAME 数据库用户名,s.PROGRAM 执行程序,s.MACHINE 死锁语句所在机器,s.STATUS 锁状态,s.LOCKWAIT 死锁描述,s.MODULE 会话客户端,s.LOGON_TIME 加锁时间,q.SQL_TEXT 脚本详情
from V$SESSION sinnerjoin V$SQL q on s.SQL_HASH_VALUE = q.HASH_VALUE
where s.SID in(select l.SESSION_IDfrom V$LOCKED_OBJECT l)and s.STATUS='ACTIVE';
杀死锁
alter system killsession'v$session.sid,v$session.serial#';