select t2.username,t2.sid,t2.serial#,t2.logon_time
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid
order by t2.logon_time;
--查死锁--
select sess.sid,sess.serial#, lo.oracle_username,lo.os_user_name,ao.object_name,lo.locked_mode
from v$locked_object lo,dba_objects ao,v$session sess
where ao.object_id = lo.object_id
and lo.session_id = sess.sid
--查死锁--
Select decode(request, 0, 'holder:', 'waiter:') || sid sid,id1,id2,lmode,request,type,ctime/60 锁定时间
from v$lock where (id1, id2, type) in
(select id1, id2, type from v$lock where request > 0) order by id1, request;
--根据sid获取进程详情--
SELECT a.username,a.machine,a.program,b.spid,a.sid,a.serial#,a.status,c.piece,c.sql_text
FROM v$session a, v$process b, v$sqltext c
WHERE a.sid = '749'
AND b.addr = a.paddr
AND a.sql_address = c.address(+)
ORDER BY c.piece;
-- add 2012-09-14
-- 数据表死锁的解决方法(转)
死锁是数据库经常发生的问题,数据库一般不会无缘无故产生死锁,死锁通常都是由于我们应用程序的设计本身造成的。产生死锁时,如何解决呢,下面是常规的解决办法:
1)执行下面SQL,先查看哪些表被锁住了:
select b.owner,b.object_name,a.session_id,a.locked_mode
from v$locked_object a,dba_objects b
where b.object_id = a.object_id;
2)查处引起死锁的会话
select b.username,b.sid,b.serial#,logon_time
from v$locked_object a,v$session b
where a.session_id = b.sid order by b.logon_time;
这里会列出SID
3) 查出SID和SERIAL#:
查V$SESSION视图:
SELECT SID,SERIAL#,PADDR FROM V$SESSION WHERE SID='刚才查到的SID';
这一步将得到PADDR
4)查V$PROCESS视图:
SELECT SPID FROM V$PROCESS WHERE ADDR='刚才查到的PADDR';
这一步得到SPID
5)杀死进程
(1)在数据库中,杀掉ORACLE进程:
ALTER SYSTEM KILL SESSION '查出的SID,查出的SERIAL#';
(2)如果在ORACLE中不能杀死进程,我们只能到操作系统中,使用操作系统命令杀死进程
KILL -9 “刚才查出的SPID”
在WINDOWS平台,可以是偶那个orakill。