日期:2014-05-16  浏览次数:20450 次

数据库数据锁定的有关问题
--数据库锁定的记录
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
where ao.object_id = lo.object_id
   and lo.session_id = sess.sid;

---140      78        MSJL          PC2011031300NIM\Administrator   NC_DELIVETOSAOUT      3
---行id   锁标识      数据库用户         哪一台机器                 被锁表             锁模式


----解锁方式,将“行id”和“锁标识”赋给下面的语句即可解锁
alter system kill session '137,455';


--锁定的数据情况
select sid,type,id1,id2,lmode,request,block from v$lock order by sid  ;

--session情况
select * from v$session where sid in (137 ,149);

--查询具体锁定与被锁定的sql语句
select wb.holding_session as 被锁定的会话id,
       sb.username as 被锁定的用户,
       qb.sql_text as 被锁定的sql语句,
       sb.machine as 被锁定的机器,
       sb.terminal,
       wb.waiting_session as 等待执行的会话id,
       sw.username as 等待执行的用户,
       qw.sql_text as 等待执行的sql语句,
       sw.machine as 等待执行的机器,
       sb.terminal,
       wb.LOCK_TYPE as 锁的类型,
       wb.mode_held,
       wb.mode_requested,
       wb.lock_id1,
       wb.lock_id2
  from dba_waiters wb,
       v$session   sb,
       v$session   sw,
       v$sqlarea   qb,
       v$sqlarea   qw
where wb.holding_session = sb.sid
   and wb.waiting_session = sw.sid
   and sb.prev_sql_addr = qb.address
   and sw.sql_address = qw.address
   and wb.mode_held <> 'None';