Oracle 查看最近 60s 资源消耗

Posted 特立独行

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle 查看最近 60s 资源消耗相关的知识,希望对你有一定的参考价值。

指定时间范围为:ASH.SAMPLE_TIME >= SYSDATE - 60 / 24 / 60 / 60),格式原因,调整为/
COL WAIT FOR 999;
COL TOTAL FOR 999;
COL IO FOR 999;
COL CPU FOR 999;
col SCHEMANAME for a16;
COL SID FOR 9999
COL MACHINE FOR A18;
COL OSUSER FOR A15;
COL PROGRAM FOR A30;
COL EVENT FOR A32;
SELECT S.SID,
       ASH.SQL_ID,
       Q.SQL_TEXT,
       S.SCHEMANAME,
       S.EVENT,
       ASH.PROGRAM,
       SUBSTR(ASH.MACHINE,
              INSTR(ASH.MACHINE, \'\' || CHR(92) || \'\', -1, 1) + 1) MACHINE,
       SUBSTR(S.OSUSER, INSTR(S.OSUSER, \'\' || CHR(92) || \'\', -1, 1) + 1) OSUSER,
       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)) "WAIT",
       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
  LEFT JOIN V$SESSION S
    ON ASH.SESSION_ID = S.SID
  LEFT JOIN V$SQL Q
    ON S.SQL_ID = Q.SQL_ID
   AND S.SQL_ADDRESS = Q.ADDRESS
   AND S.SQL_HASH_VALUE = Q.HASH_VALUE
 WHERE ASH.SAMPLE_TIME >= SYSDATE - 60 / (24 * 60 * 60)
 GROUP BY S.SID,
          S.SCHEMANAME,
          ASH.SQL_ID,
          Q.SQL_TEXT,
          S.EVENT,
          ASH.PROGRAM,
          SUBSTR(ASH.MACHINE,
                 INSTR(ASH.MACHINE, \'\' || CHR(92) || \'\', -1, 1) + 1),
          SUBSTR(S.OSUSER, INSTR(S.OSUSER, \'\' || CHR(92) || \'\', -1, 1) + 1)
HAVING SUM(DECODE(ASH.SESSION_STATE, \'ON CPU\', 1, 1)) > = 2
 ORDER BY SUM(DECODE(ASH.SESSION_STATE, \'ON CPU\', 1, 1)) DESC;

以上是关于Oracle 查看最近 60s 资源消耗的主要内容,如果未能解决你的问题,请参考以下文章

oracle查询消耗服务器资源SQL语句

mysql通过my profile查看sql消耗资源的情况

怎样查看最消耗资源的sql语句 与 ora

oracle sql资源消耗相关视图

ORACLE优化查询资源消耗的语句

Oracle-SQL程序优化3