在进行数据库管理的过程中,经常会出现数据表被用户的一些不合理操作而导致表被锁定的情况,以下主要介绍如何查找哪些表被哪个用户所锁定,以及如何解除锁定:
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;
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;
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;
2.确定锁定表用户的sid与serial编号(可通过oracle用户确定也可通过系统用户确定)
a.通过oracle用户确定
select sid,serial# from v$session where username=’center’;
b.通过系统用户确定
select sid,serial# from v$session where username=’administrator’;
3.杀掉造成死锁的进程(已知是123阻塞了124号进程,杀掉即可解锁)
alter system kill session ‘123,3935’;
至此表死锁解除,现在存在的是数据表正常的锁定,等事务提交后自然消失.
转载于:https://blog.51cto.com/tianzt/263195