Oracle查看进程堵塞

Oracle查看进程堵塞

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
      , --THE BLOCKED 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 --BLOCK THE OTHER SQL
   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;

你可能感兴趣的:(Oracle,oracle,运维,sql)