zoukankan      html  css  js  c++  java
  • oracle查询消耗服务器资源SQL语句

    1、查找最近一天内,最消耗CPU的SQL语句

    SELECT ASH.INST_ID,
           ASH.SQL_ID,
           (SELECT VS.SQL_TEXT
              FROM GV$SQLAREA VS
             WHERE VS.SQL_ID = ASH.SQL_ID
               AND ASH.INST_ID = VS.INST_ID) SQL_TEXT,
           ASH.SQL_CHILD_NUMBER,
           ASH.SQL_OPNAME,
           ASH.SESSION_INFO,
           COUNTS,
           PCTLOAD * 100 || '%' PCTLOAD
      FROM (SELECT ASH.INST_ID,
                   ASH.SQL_ID,
                   ASH.SQL_CHILD_NUMBER,
                   ASH.SQL_OPNAME,
                   (ASH.MODULE || '--' || ASH.ACTION || '--' || ASH.PROGRAM || '--' ||
                   ASH.MACHINE || '--' || ASH.CLIENT_ID || '--' ||
                   ASH.SESSION_TYPE) SESSION_INFO,
                   COUNT(*) COUNTS,
                   ROUND(COUNT(*) / SUM(COUNT(*)) OVER(), 2) PCTLOAD,
                   DENSE_RANK() OVER(ORDER BY COUNT(*) DESC) RANK_ORDER
              FROM GV$ACTIVE_SESSION_HISTORY ASH
             WHERE ASH.SESSION_TYPE <> 'BACKGROUND'
               AND ASH.SESSION_STATE = 'ON CPU'
               AND SAMPLE_TIME > SYSDATE - 1
             GROUP BY ASH.INST_ID,
                      ASH.SQL_ID,
                      ASH.SQL_CHILD_NUMBER,
                      ASH.SQL_OPNAME,
                      (ASH.MODULE || '--' || ASH.ACTION || '--' || ASH.PROGRAM || '--' ||
                      ASH.MACHINE || '--' || ASH.CLIENT_ID || '--' ||
                      ASH.SESSION_TYPE)) ASH
     WHERE RANK_ORDER <= 10
     ORDER BY COUNTS DESC;

    2、查找最近一天内,最消耗CPU的会话

    SELECT SESSION_ID, COUNT(*)
      FROM V$ACTIVE_SESSION_HISTORY V
     WHERE V.SESSION_STATE = 'ON CPU'
       AND V.SAMPLE_TIME > SYSDATE - 1
     GROUP BY SESSION_ID
     ORDER BY COUNT(*) DESC;

    3、查找最近一天内,最消耗I/O的SQL语句

    SELECT ASH.INST_ID,
           ASH.SQL_ID,
           (SELECT VS.SQL_TEXT
              FROM GV$SQLAREA VS
             WHERE VS.SQL_ID = ASH.SQL_ID
               AND ASH.INST_ID = VS.INST_ID) SQL_TEXT,
           ASH.SQL_CHILD_NUMBER,
           ASH.SQL_OPNAME,
           ASH.SESSION_INFO,
           COUNTS,
           PCTLOAD * 100 || '%' PCTLOAD
      FROM (SELECT ASH.INST_ID,
                   ASH.SQL_ID,
                   ASH.SQL_CHILD_NUMBER,
                   ASH.SQL_OPNAME,
                   (ASH.MODULE || '--' || ASH.ACTION || '--' || ASH.PROGRAM || '--' ||
                   ASH.MACHINE || '--' || ASH.CLIENT_ID || '--' ||
                   ASH.SESSION_TYPE) SESSION_INFO,
                   COUNT(*) COUNTS,
                   ROUND(COUNT(*) / SUM(COUNT(*)) OVER(), 2) PCTLOAD,
                   DENSE_RANK() OVER(ORDER BY COUNT(*) DESC) RANK_ORDER
              FROM GV$ACTIVE_SESSION_HISTORY ASH
             WHERE ASH.SESSION_TYPE <> 'BACKGROUND'
               AND ASH.SESSION_STATE = 'WAITING'
               AND ASH.SAMPLE_TIME > SYSDATE - 1
               AND ASH.WAIT_CLASS = 'USER I/O'
             GROUP BY ASH.INST_ID,
                      ASH.SQL_ID,
                      ASH.SQL_CHILD_NUMBER,
                      ASH.SQL_OPNAME,
                      (ASH.MODULE || '--' || ASH.ACTION || '--' || ASH.PROGRAM || '--' ||
                      ASH.MACHINE || '--' || ASH.CLIENT_ID || '--' ||
                      ASH.SESSION_TYPE)) ASH
     WHERE RANK_ORDER <= 10
     ORDER BY COUNTS DESC;

    4、查找最近一天内,最消耗资源的SQL语句

    SELECT ASH.INST_ID,
           ASH.SQL_ID,
           (SELECT VS.SQL_TEXT
              FROM GV$SQLAREA VS
             WHERE VS.SQL_ID = ASH.SQL_ID
               AND ASH.INST_ID = VS.INST_ID) SQL_TEXT,
           ASH.SQL_CHILD_NUMBER,
           ASH.SQL_OPNAME,
           ASH.SESSION_INFO,
           COUNTS,
           PCTLOAD * 100 || '%' PCTLOAD
      FROM (SELECT ASH.INST_ID,
                   ASH.SQL_ID,
                   ASH.SQL_CHILD_NUMBER,
                   ASH.SQL_OPNAME,
                   (ASH.MODULE || '--' || ASH.ACTION || '--' || ASH.PROGRAM || '--' ||
                   ASH.MACHINE || '--' || ASH.CLIENT_ID || '--' ||
                   ASH.SESSION_TYPE) SESSION_INFO,
                   COUNT(*) COUNTS,
                   ROUND(COUNT(*) / SUM(COUNT(*)) OVER(), 2) PCTLOAD,
                   DENSE_RANK() OVER(ORDER BY COUNT(*) DESC) RANK_ORDER
              FROM GV$ACTIVE_SESSION_HISTORY ASH
             WHERE ASH.SESSION_TYPE <> 'BACKGROUND'
               AND ASH.SESSION_STATE = 'WAITING'
               AND ASH.SAMPLE_TIME > SYSDATE - 1
               AND ASH.WAIT_CLASS = 'USER I/O'
             GROUP BY ASH.INST_ID,
                      ASH.SQL_ID,
                      ASH.SQL_CHILD_NUMBER,
                      ASH.SQL_OPNAME,
                      (ASH.MODULE || '--' || ASH.ACTION || '--' || ASH.PROGRAM || '--' ||
                      ASH.MACHINE || '--' || ASH.CLIENT_ID || '--' ||
                      ASH.SESSION_TYPE)) ASH
     WHERE RANK_ORDER <= 10
     ORDER BY COUNTS DESC;

    5、查找最近一天内,最消耗资源的会话

    SELECT ASH.SESSION_ID,
           ASH.SESSION_SERIAL#,
           ASH.USER_ID,
           ASH.PROGRAM,
           SUM(DECODE(ASH.SESSION_STATE, 'ON CPU', 1, 0)) "CPU",
           SUM(DECODE(ASH.SESSION_STATE, 'WAITING', 1, 0)) -
           SUM(DECODE(ASH.SESSION_STATE,
                      'WAITING',
                      DECODE(ASH.WAIT_CLASS, 'USER I/O', 1, 0),
                      0)) "WAITING",
           SUM(DECODE(ASH.SESSION_STATE,
                      'WAITING',
                      DECODE(ASH.WAIT_CLASS, 'USER I/O', 1, 0),
                      0)) "IO",
           SUM(DECODE(ASH.SESSION_STATE, 'ON CPU', 1, 1)) "TOTAL"
      FROM V$ACTIVE_SESSION_HISTORY ASH
     WHERE ASH.SAMPLE_TIME > SYSDATE - 1
     GROUP BY ASH.SESSION_ID, ASH.USER_ID, ASH.SESSION_SERIAL#, ASH.PROGRAM
     ORDER BY SUM(DECODE(ASH.SESSION_STATE, 'ON CPU', 1, 1));
  • 相关阅读:
    xx系统需求分析第七稿--权限管理(一)
    第四周学习进度总结
    hbase的Shell命令操作
    软件需求最佳实践读书笔记一
    hbase的Java基本操作
    Java 面向对象编程之接口
    Java 面向对象编程之继承的super关键词
    Java核心基础之数据类型
    Java 导出Excel
    JavaSE基础知识之修饰符和使用场景,你真的了解嘛
  • 原文地址:https://www.cnblogs.com/beanbag/p/10570527.html
Copyright © 2011-2022 走看看