欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle锁处理、解锁方法

程序员文章站 2022-03-21 19:38:55
1、查询锁情况 2、根据SID查询具体信息(可忽略) 3、杀掉会话 #根据1和2中查到的SID和SERIAL# 定位会话,并杀掉 或 附件: #查询阻塞脚本 col waiting_session for a20 col lock_type for a15 col mode_requested fo ......

1、查询锁情况

select sid,serial#,event,blocking_session from v$session where event like '%tx%';

2、根据sid查询具体信息(可忽略)

select sid,serial#,username,machine,blocking_session from v$session where sid=<sid>;

3、杀掉会话

#根据1和2中查到的sid和serial# 定位会话,并杀掉

alter system disconnect session '<sid>,<serial>' immediate;

alter system kill session '<sid>,<serial>';

 附件:

#查询阻塞脚本

col waiting_session for a20
col lock_type for a15
col mode_requested for a10
col mode_held for a10
col lock_id1 for a10
col lock_id2 for a10
set linesize 120
set pagesize 999
with dba_locks_cust as 
(select  inst_id||'_'||sid session_id,
      decode (type,
          'mr', 'media recovery',
          'rt', 'redo thread',
          'un', 'user name',
          'tx', 'transaction',
          'tm', 'dml',
          'ul', 'pl/sql user lock',
          'dx', 'distributed xaction',
          'cf', 'control file',
          'is', 'instance state',
          'fs', 'file set',
          'ir', 'instance recovery',
          'st', 'disk space transaction',
          'ts', 'temp segment',
          'iv', 'library cache invalidation',
          'ls', 'log start or switch',
          'rw', 'row wait',
          'sq', 'sequence number',
          'te', 'extend table',
          'tt', 'temp table',
          type)
        lock_type,
      decode (lmode,
          0, 'none',            /* mon lock equivalent */
          1, 'null',                     /* n */
          2, 'row-s (ss)',                  /* l */
          3, 'row-x (sx)',                  /* r */
          4, 'share',                    /* s */
          5, 's/row-x (ssx)',                /* c */
          6, 'exclusive',                  /* x */
          to_char (lmode))
        mode_held,
      decode (request,
          0, 'none',            /* mon lock equivalent */
          1, 'null',                     /* n */
          2, 'row-s (ss)',                  /* l */
          3, 'row-x (sx)',                  /* r */
          4, 'share',                    /* s */
          5, 's/row-x (ssx)',                /* c */
          6, 'exclusive',                  /* x */
          to_char (request))
        mode_requested,
      to_char (id1) lock_id1,
      to_char (id2) lock_id2,
      ctime last_convert,
      decode (block,
          0, 'not blocking', /* not blocking any other processes */
          1, 'blocking',   /* this lock blocks other processes */
          2, 'global',  /* this lock is global, so we can't tell */
          to_char (block))
        blocking_others
   from gv$lock
),
lock_temp as
(select * from dba_locks_cust),
lock_holder as 
(
 select w.session_id waiting_session,
    h.session_id holding_session,
    w.lock_type,
    h.mode_held,
    w.mode_requested,
    w.lock_id1,
    w.lock_id2
 from lock_temp w, lock_temp h
 where h.blocking_others in ('blocking','global')
 and h.mode_held   != 'none'
 and h.mode_held   != 'null'
 and w.mode_requested != 'none'
 and w.lock_type    = h.lock_type
 and w.lock_id1    = h.lock_id1
 and w.lock_id2    = h.lock_id2
),
lock_holders as
(select waiting_session,holding_session,lock_type,mode_held,
mode_requested,lock_id1,lock_id2
 from lock_holder
 union all
 select holding_session, null, 'none', null, null, null, null 
  from lock_holder
 minus
 select waiting_session, null, 'none', null, null, null, null
  from lock_holder 
 )
select lpad(' ',3*(level-1)) || waiting_session waiting_session,
    lock_type,
    mode_requested,
    mode_held,
    lock_id1,
    lock_id2
 from lock_holders
connect by prior waiting_session = holding_session
 start with holding_session is null;

总结

以上所述是小编给大家介绍的oracle锁处理、解锁方法,希望对大家有所帮助