1. 程式人生 > >Oracle檢視被鎖問題

Oracle檢視被鎖問題

--首先檢視有哪些鎖
selec 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 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#';