zoukankan      html  css  js  c++  java
  • Oracle RAC阻塞排查SQL脚本

    该使用到的sql脚本是参考别人技术文档转接过来用于日常工作中使用到的记录下。

    1,树形结构分级别显示会话之间的阻塞关系

    set lines 200 pages 100
    col tree for a30
    col event for a40
    select *
      from (select a.inst_id, a.sid, a.serial#,
                   a.sql_id,
                   a.event,
                   a.status,
                   connect_by_isleaf as isleaf,
                   sys_connect_by_path(a.SID||'@'||a.inst_id, ' <- ') tree,
                   level as tree_level
              from gv$session a
             start with a.blocking_session is not null
            connect by (a.sid||'@'||a.inst_id) = prior (a.blocking_session||'@'||a.blocking_instance))
     where isleaf = 1
     order by tree_level asc;

    效果如下:

    2,直接显示会话阻塞关系

    SELECT DISTINCT  
              s1.username  
           || '@'  
           || s1.machine  
           || ' ( INST='  
           || s1.inst_id  
           || ' SID='  
           || s1.sid  
           || ' Serail#='  
           || s1.serial#  
           || ' ) IS BLOCKING '  
           || s2.username  
           || '@'  
           || s2.machine  
           || ' ( INST='  
           || s2.inst_id  
           || ' SID='  
           || s2.sid  
           || ' Serial#='  
           || s2.serial#  
           || ' ) '  
              AS blocking_status  
      FROM gv$lock l1,  
           gv$session s1,  
           gv$lock l2,  
           gv$session s2  
     WHERE     s1.sid = l1.sid  
           AND s2.sid = l2.sid  
           AND s1.inst_id = l1.inst_id  
           AND s2.inst_id = l2.inst_id  
           AND l1.block > 0  
           AND l2.request > 0  
           AND l1.id1 = l2.id1  
           AND l1.id2 = l2.id2;

    效果如下:

    3,显示阻塞实例的sql语句(需要在RAC的每个实例上面去执行)

    select b.sid,
           a.sql_id,
           a.sql_text,
           a.hash_value,
           b.username,
           b.machine,
           a.module,
           decode(c.block, 1, 'blocking') blocking,
           decode(c.request, 0, 'null', 'blocked') blocked,
           to_char(b.logon_time, 'yyyy-mm-dd hh24:mi:ss')
      from v$sql a, v$session b, v$lock c
     where c.type = 'TX'
       and a.sql_id = b.sql_id
       and b.sid = c.sid
    union all
    select b.sid,
           a.sql_id,
           a.sql_text,
           a.hash_value,
           b.username,
           b.machine,
           a.module,
           decode(c.block, 1, 'blocking') blocking,
           decode(c.request, 0, 'null', 'blocked') blocked,
           to_char(b.logon_time, 'yyyy-mm-dd hh24:mi:ss')
      from v$sql a, v$session b, v$lock c
     where c.type = 'TX'
       and a.sql_id = b.prev_sql_id
       and b.sid = c.sid
       and c.block = 1;

    效果如下:

  • 相关阅读:
    c#之添加window服务(定时任务)
    dotnet core 之 CORS使用示例
    CORS讲解
    vim的多文件编辑和多窗口功能
    vim操作常用命令总结
    vmware的三种网络模式讲解
    vmware下的linux没有网络问题解决思路
    asp.net core 系列之允许跨域访问2之测试跨域(Enable Cross-Origin Requests:CORS)
    asp.net core 系列之允许跨域访问-1(Enable Cross-Origin Requests:CORS)
    asp.net core 系列之允许跨域访问(Enable Cross-Origin Requests:CORS)
  • 原文地址:https://www.cnblogs.com/hcyjjp/p/10097525.html
Copyright © 2011-2022 走看看