zoukankan      html  css  js  c++  java
  • 检测数据库各实例session 阻塞 tree的sql

    DBA的日常功能SQL之一,绝对原创。


    由于使用到了 v$sesion 的 blocking_instance,blocking_session 这两列,所以数据库的最低版本为oracle 10g。


    适合单实例和多实实例数据库,一个SQL搞定。



    with/*+ materialized +*/ aa as (
          select *
          from gv$session s
          where 1=1
    )
    select 
          'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
          lpad('+', 2 * level - 1) ||t.inst_sid as leveL_inst_sid,
          level level_flag,
          sys_connect_by_path(t.inst_sid,'/') as inst_sid_path,
          connect_by_root t.inst_sid as root_inst_sid,
          connect_by_isleaf as node_isleaf,
          '##########' as FLAGFLAG0, 
           t.status, 
           t.event#, 
           t.event, 
           t.program,
           t.module,
           t.action,
           t.client_identifier,
           t.OSUSER os_USER,
           t.machine os_machine,
           t.logon_time logon_time,
           t.last_call_et last_call_et,
           'alter system kill session ''' || t.SID || ',' || t.SERIAL# || ''' immediate;' as kill_SID,
          '##########' as FLAGFLAG/*,
          t.*  */

    from (
            select gs.inst_id||'-'||gs.sid as inst_sid,
                   gs.blocking_instance||'-'||gs.blocking_session par_inst_sid,
                   gs.*
              from aa gs
             where 1=1
               and (gs.inst_id,gs.sid ) in (
                        --被阻塞者
                        select s.inst_id,s.sid
                        from aa s
                        where 1=1
                        and s.BLOCKING_SESSION is not null
                        union all         
                        --阻塞者
                        select sw.inst_id,sw.sid
                        from aa sw
                        where 1=1
                        --and lower(sw.MACHINE) not like '%ejb%'
                        and (sw.INST_ID,sw.SID) in (
                            select/*+ hash_sj*/ 
                                   s.BLOCKING_INSTANCE,
                                   s.BLOCKING_SESSION
                            from aa s
                            where 1=1
                            and s.BLOCKING_SESSION is not null
                        )    
            )   
         ) t
    where 1=1
     connect by prior t.inst_sid =t.par_inst_sid 
    order siblings by t.inst_sid  
    ;




  • 相关阅读:
    HashMap源码解读(转)
    使用javascript开发2048
    程序猿接私活经验总结,来自csdn论坛语录
    Cocos2d-x实例:设置背景音乐与音效- AppDelegate实现
    Jenkins(二)
    SVN高速新手教程
    Visio Premium 2010密钥+破解激活方法
    oracle中LAG()和LEAD()等分析统计函数的使用方法(统计月增长率)
    shell语法简单介绍
    memset函数具体说明
  • 原文地址:https://www.cnblogs.com/ctypyb2002/p/9793183.html
Copyright © 2011-2022 走看看