大可 • Duke

专注,谦逊,分享

oracle表被锁(delete或update一直处于执行状态)的处理办法。

--首先查看有哪些锁
select /*+ rule */ s.username,
      decode(l.type,'TM','TABLE LOCK','TX','ROW LOCK',null) lock_level,
      o.owner,
      o.object_name,
      o.object_type,
      s.sid,s.serial#,
      s.terminal,
      s.machine,
      s.program,
      s.osuser
from v$session s,v$lock l,dba_objects o
where l.sid = s.sid
and l.id1 = o.object_id(+)
and s.username is not null

--如果发生了锁等待,看是谁锁了表而引起谁的等待
--以下的语句可以查询到谁锁了表,而谁在等待。 如果有子节点,则表示有等待发生
select /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username user_name,
       o.owner,
       o.object_name,
       o.object_type,
       s.sid,
       s.serial#
from v$locked_object l,dba_objects o,v$session s
where l.object_id=o.object_id
and l.session_id=s.sid
order by o.object_id,xidusn desc


--找到引起等待的session,杀掉该session:
alter system kill session 'sid,serial#';

  

posted @ 2014-10-27 08:32  大可·Duke  阅读(8714)  评论(0编辑  收藏  举报