摘自:https://www.cnblogs.com/xuke/p/4053396.html
http://blog.itpub.net/30036720/viewspace-2121034/
oracle表被锁(delete或update一直处于执行状态)的处理办法。
1 --首先查看有哪些锁 2 select /*+ rule */ s.username, 3 decode(l.type,'TM','TABLE LOCK','TX','ROW LOCK',null) lock_level, 4 o.owner, 5 o.object_name, 6 o.object_type, 7 s.sid,s.serial#, 8 s.terminal, 9 s.machine, 10 s.program, 11 s.osuser 12 from v$session s,v$lock l,dba_objects o 13 where l.sid = s.sid 14 and l.id1 = o.object_id(+) 15 and s.username is not null 16 17 --如果发生了锁等待,看是谁锁了表而引起谁的等待 18 --以下的语句可以查询到谁锁了表,而谁在等待。 如果有子节点,则表示有等待发生 19 select /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username user_name, 20 o.owner, 21 o.object_name, 22 o.object_type, 23 s.sid, 24 s.serial# 25 from v$locked_object l,dba_objects o,v$session s 26 where l.object_id=o.object_id 27 and l.session_id=s.sid 28 order by o.object_id,xidusn desc 29 30 31 --找到引起等待的session,杀掉该session: 32 alter system kill session 'sid,serial#';
分类: Oracle
2016-06-27 10:30:36
1. ORACLE中查看当前系统中锁表情况
select * from v$locked_object
可以通过查询v$locked_object拿到sid和objectid,然后用sid和v$session链表查询是哪里锁的表,用v$session中的objectid字段和dba_objects的id字段关联,查询详细的锁表情况。
查询SQL如下:
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, v$process p
where ao.object_id = lo.object_id
and lo.session_id = sess.sid;
查询是什么SQL引起了锁表的原因,SQL如下:
select l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
s.user#,
l.os_user_name,
s.machine,
s.terminal,
a.sql_text,
a.action
from v$sqlarea a, v$session s, v$locked_object l
where l.session_id = s.sid
and s.prev_sql_addr = a.address
order by sid, s.serial#;
2. ORACLE解锁的方法
alter system kill session ’146′; –146为锁住的进程号,即spid