一条查询Oracle中的阻塞锁(以及阻塞在哪个数据上)的SQL

Select '节点 ' || a.INST_ID || ' session ' || a.sid || ',' || a_s.SERIAL# ||
       ' 阻塞了 节点 ' || b.INST_ID || ' session ' || b.SID || ',' || b_s.SERIAL# blockinfo,
       a.INST_ID,
       a_s.SID,
       a_s.SCHEMANAME,
       a_s.MODULE,
       a_s.STATUS,
       a.type lock_type,
       a.id1,
       a.id2,
       decode(a.lmode,
              0,
              'none',
              1,
              null,
              2,
              'row-S (SS)',
              3,
              'row-X (SX)',
              4,
              'share (S)',
              5,
              'S/Row-X (SSX)',
              6,
              'exclusive (X)') lock_mode,
       
       '后为被阻塞信息' ,
       b.INST_ID blocked_inst_id,
       b_s.SID blocked_sid,
       b.TYPE blocked_lock_type,
       decode(b.request,
              0,
              'none',
              1,
              null,
              2,
              'row-S (SS)',
              3,
              'row-X (SX)',
              4,
              'share (S)',
              5,
              'S/Row-X (SSX)',
              6,
              'exclusive (X)') blocked_lock_request,
       b_s.SCHEMANAME blocked_SCHEMANAME,
       b_s.MODULE blocked_module,
       b_s.STATUS blocked_status,
       b_s.SQL_ID blocked_sql_id,
       obj.owner blocked_owner,
       obj.object_name blocked_object_name,
       obj.OBJECT_TYPE blocked_OBJECT_TYPE,
       case
          when b_s.ROW_WAIT_OBJ# <> -1 then
             dbms_rowid.rowid_create(1,
                                     obj.DATA_OBJECT_ID,
                                     b_s.ROW_WAIT_FILE#,
                                     b_s.ROW_WAIT_BLOCK#,
                                     b_s.ROW_WAIT_ROW#) 
          else 
            '-1' 
          end blocked_rowid, --被阻塞数据的rowid
       decode(obj.object_type,
              'TABLE',
              'select * from ' || obj.owner || '.' || obj.object_name ||
              ' where rowid=''' ||
              dbms_rowid.rowid_create(1,
                                      obj.DATA_OBJECT_ID,
                                      b_s.ROW_WAIT_FILE#,
                                      b_s.ROW_WAIT_BLOCK#,
                                      b_s.ROW_WAIT_ROW#) || '''',
              NULL)  blocked_data_querysql  from gv$lock     a,
       gv$lock     b,
       gv$session  a_s,
       gv$session  b_s,
       dba_objects obj
 where a.id1 = b.id1
   and a.id2 = b.id2
   and a.BLOCK > 0 --阻塞了其他人
   and b.request > 0
   and ((a.INST_ID = b.INST_ID and a.sid <> b.sid) or
       (a.INST_ID <> b.INST_ID))
   and a.sid = a_s.sid
   and a.INST_ID = a_s.INST_ID
   and b.sid = b_s.sid
   and b.INST_ID = b_s.INST_ID
   and b_s.ROW_WAIT_OBJ# = obj.object_id(+)
 order by a.inst_id,a.sid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值