oracle表被session锁住,解决办法

--首先查看有哪些锁

select/*+rule*/s.username,

decode(l.type,'TM','TABLELOCK','TX','ROWLOCK',null)lock_level,

o.owner,

o.object_name,

o.object_type,

s.sid,s.serial#,

s.terminal,

s.machine,

s.program,

s.osuser

fromv$sessions,v$lockl,dba_objectso

wherel.sid=s.sid

andl.id1=o.object_id(+)

ands.usernameisnotnull

--如果发生了锁等待,看是谁锁了表而引起谁的等待

--以下的语句可以查询到谁锁了表,而谁在等待。如果有子节点,则表示有等待发生

select/*+rule*/lpad('',decode(l.xidusn,0,3,0))||l.oracle_usernameuser_name,

o.owner,

o.object_name,

o.object_type,

s.sid,

s.serial#

fromv$locked_objectl,dba_objectso,v$sessions

wherel.object_id=o.object_id

andl.session_id=s.sid

orderbyo.object_id,xidusndesc

--找到引起等待的session,杀掉该session:

altersystemkillsession'sid,serial#';

相关推荐