zoukankan      html  css  js  c++  java
  • 使用ASH监控历史会话,找出坏SQL

    使用如下脚本可以监控历史会话经历过哪些等待事件,并且按照等待次数降序排列

    select session_id,event,count(*),sum(time_waited) from v$active_session_history where  session_state='WAITING'
    and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
    group by session_id,event order by 3 desc;
    例子:

    SQL> select session_id,event,count(*),sum(time_waited) from v$active_session_history where  session_state='WAITING'
      2  and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
      3  group by session_id,event order by 3 desc;
    输入 howlongago 的值:  5
    原值    2: and time_waited>0 and sample_time>=(sysdate-&howlongago/(24*60))
    新值    2: and time_waited>0 and sample_time>=(sysdate-5/(24*60))

    SESSION_ID EVENT                            COUNT(*) SUM(TIME_WAITED)
    ---------- ------------------------------ ---------- ----------------
           150 direct path write temp                  3            20825
           165 control file sequential read            2            21520
           150 direct path read temp                   2            38545

    然后通过如下语句查询出引起该等待事件的sql_id

    select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid;


    SQL> select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid;
    输入 howlongago 的值:  8
    输入 sid 的值:  150
    原值    1: select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-&howlongago/(24*60)) and session_id=&sid
    新值    1: select event, session_id,sql_id, p1,p2,p3 from v$active_session_history where sample_time>=(sysdate-8/(24*60)) and session_id=150

    EVENT                          SESSION_ID SQL_ID                P1         P2
    ------------------------------ ---------- ------------- ---------- ----------
            P3
    ----------
    direct path read temp                 150 fqu3bkz2q6j26        201      58665
             1

                                          150 fqu3bkz2q6j26 1111838976          1
             0

    direct path read temp                 150 fqu3bkz2q6j26        201      45897
             1


    EVENT                          SESSION_ID SQL_ID                P1         P2
    ------------------------------ ---------- ------------- ---------- ----------
            P3
    ----------
    direct path read temp                 150 fqu3bkz2q6j26        201      47753
             1

    再通过如下语句找到引起该等待事件的SQL

    select sql_text from v$sqlarea where sql_id='&sql_id';

    SQL> select sql_text from v$sqlarea where sql_id='&sql_id';
    输入 sql_id 的值:  fqu3bkz2q6j26
    原值    1: select sql_text from v$sqlarea where sql_id='&sql_id'
    新值    1: select sql_text from v$sqlarea where sql_id='fqu3bkz2q6j26'

    SQL_TEXT
    --------------------------------------------------------------------------------
    select a.* from dict a,dict b order by 1

  • 相关阅读:
    gvim在windows下的一些小技巧
    解决eclipse在ubuntu下无法找到jdk方法
    ubuntu 12.04 下安装wireshark
    使用坚果云同步数据
    Windows WMIC命令详解 (Windows Management Instrumentation Commandline)
    ubuntu 12.04 配置指南
    CHROME自定义样式扩展 —— STYLISH
    地漏
    卫生间装修,想要坐便改成蹲便,地面需要加高多少?
    不锈钢橱柜
  • 原文地址:https://www.cnblogs.com/hehe520/p/6330662.html
Copyright © 2011-2022 走看看