table locked 怎么办? 就这样

查出是什么哪个sid,serial锁住了哪个表。

假设: unlock table test in exclusive mode

---------------------------------------------------------------

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

如果发生了锁等待,我们可能更想知道是谁锁了表而引起谁的等待
以上的语句可以查询到谁锁了表,而谁在等待。
以上查询结果是一个树状结构,如果有子节点,则表示有等待发生。
如果想知道锁用了哪个回滚段,还可以关联到V$rollname,其中xidusn就是回滚段的USN

-----------------------------------------------------------------

SELECT l.session_id sid, s.serial#, l.locked_mode,l.oracle_username,
l.os_user_name,s.machine, s.terminal, o.object_name, s.logon_time
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid, s.serial#

-------------------------------------------------------------------

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#;

结果:用户信息更具体

SID SERIAL# LOCKED_MODE ORACLE_USERNAME USER# OS_USER_NAME MACHINE TERMINAL SQL_TEXT ACTION

125 62647 6 SCOTT 54 Administrator WORKGROUP\TNSPING TNSPING lock   table   test   in   exclusive   mode   nowait
125 62647 6 SCOTT 54 Administrator WORKGROUP\TNSPING TNSPING lock   table   test   in   exclusive   mode   nowait

---------------------------------------------------------------------------------

然后kill 掉这个会话。

desc v$session

alter system kill session '125,59933';

--------------------------------------------------------------------------------

SELECT s.sid, s.serial#, s.username, s.schemaname, s.osuser, s.process, s.machine,
s.terminal, s.logon_time, l.type
FROM v$session s, v$lock l
WHERE s.sid = l.sid;

posted on 2009-04-23 16:29  fengyuwuzu1980  阅读(153)  评论(0编辑  收藏  举报

导航