Oracle中表死锁的处理
在进行Oracle数据库管理的过程中,经常会出现数据表被用户的一些不合理操作而导致表被锁定的情况,以下主要介绍如何查找哪些表被哪个用户所锁定,以及如何解除锁定:
1.查找被锁定的表:
select object_name,session_id,os_user_name,oracle_username,process,locked_mode,status
from v$locked_object l, all_objects a
where l.object_id=a.object_id;
如果想知道具体是哪个进程阻塞了哪个进程,可用以下语句查看:
select username,v$lock.sid,trunc(id1/power(2,16)) rbs,bitand(id1,to_number('ffff','xxxx'))+0 slot,id2 seq,lmode,request from v$lock, v$session where v$lock.type = 'TX' and v$lock.sid = v$session.sid and v$session.username = 'CENTER' ;
或
select
(select username||':'||sid||':'||serial# from v$session where sid=a.sid) ||
' 阻塞了 ' ||
(select username ||':'||sid||':'||serial# from v$session where sid=b.sid)
from v$lock a, v$lock b
where a.block = 1
and b.request > 0
and a.id1 = b.id1
and a.id2 = b.id2;