Oracle中查看锁表情况的Sql语句

2011-10-30 by Jinyang | Filed under Oracle.
SELECT S.SID SESSION_ID, S.USERNAME, DECODE(LMODE,0,’None’,1,’Null’,2,’Row-S (SS)’,
3,’Row-X (SX)’,4,’Share’,5,’S/Row-X (SSX)’,6,’Exclusive’,TO_CHAR(LMODE)) MODE_HELD,
DECODE(REQUEST,0,’None’,1,’Null’,2,’Row-S (SS)’,3,’Row-X (SX)’,4,’Share’,5,’S/Row-X (SSX)’,6,
‘Exclusive’,TO_CHAR(REQUEST)) MODE_REQUESTED, O.OWNER||’.’||O.OBJECT_NAME||'(‘||O.OBJECT_TYPE||’)’,
S.TYPE LOCK_TYPE, L.ID1 LOCK_ID1, L.ID2 LOCK_ID2
FROM  V$LOCK L, SYS.DBA_OBJECTS O, V$SESSION S
WHERE  L.SID  =  S.SID  AND   L.ID1  =  O. OBJECT_ID;
SELECT S.SID SESSION_ID, S.USERNAME, DECODE(LMODE,0,’None’,1,’Null’,2,’Row-S (SS)’,  3,’Row-X (SX)’,4,’Share’,5,’S/Row-X (SSX)’,6,’Exclusive’,TO_CHAR(LMODE)) MODE_HELD,   DECODE(REQUEST,0,’None’,1,’Null’,2,’Row-S (SS)’,3,’Row-X (SX)’,4,’Share’,5,’S/Row-X (SSX)’,6,  ‘Exclusive’,TO_CHAR(REQUEST)) MODE_REQUESTED, O.OWNER||’.’||O.OBJECT_NAME||'(‘||O.OBJECT_TYPE||’)’,   S.TYPE LOCK_TYPE, L.ID1 LOCK_ID1, L.ID2 LOCK_ID2 FROM  V$LOCK L, SYS.DBA_OBJECTS O, V$SESSION S WHERE  L.SID  =  S.SID  AND   L.ID1  =  O. OBJECT_ID;
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


发表评论

您的电子邮箱不会被公开。 标记为 * 的区域必须填写

返回顶部