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));

原文地址:https://www.cnblogs.com/beanbag/p/10570527.html

时间: 2024-10-05 05:50:10

oracle查询消耗服务器资源SQL语句的相关文章

ORACLE将执行过的SQL语句存放在内存的共享池

Oracle SQL性能优化深入浅出 ORACLE将执行过的SQL语句存放在内存的共享池(shared buffer pool)中,可以被所有的数据库用户共享.当你执行一个SQL语句(有时被称为一个游标)时,如果它和之前的执行过的语句完全相同,ORACLE就能很快获得已经被解析的语句以及最好的执行路径. 这个功能大大地提高了SQL的执行性能并节省了内存的使用. 为了不重复解析相同的SQL语句,在第一次解析之后,Oracle将SQL语句存放在内存中.这块位于系统全局区域SGA(systemglob

几个常用ORACLE运维监控的SQL语句

1.消耗CPUSELECT a.CPU_TIME, --CPU时间 百万分之一(微秒)              a.OPTIMIZER_MODE,--优化方式              a.EXECUTIONS,--执行次数              a.DISK_READS,--读盘次数              a.SHARABLE_MEM,--占用shared pool的内存多少              a.BUFFER_GETS,--读取缓冲区的次数              a.C

oracle查询最占用资源的查询

从V$SQLAREA中查询最占用资源的查询 select b.username username,a.disk_reads reads,a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions) rds_exec_ratio,a.sql_text Statementfrom  v$sqlarea a,dba_users bwhere a.parsing_user_id=b.user_idand a.disk_reads

【转】Oracle如何复制表的sql语句

原文链接 http://database.51cto.com/art/201004/192790.htm 以下的文章主要是介绍Oracle复制表的sql语句,其中包括如何复制表结构的sql.以及如何复制相关表的结构又复制表中的数据sql. 如下,表a是数据库中已经存在的表,b是准备根据表a进行复制创建的表: 1.只复制表结构的sql create table b as select * from a where 1<>1 2.即复制表结构又复制表中数据的sql create table b a

如何监控MYSQL消耗服务器资源

http://258xiaolei-sina-com.iteye.com/blog/764665 启动Mysql时加参数--log-slow-queries来记录执行时间超过long_query_time秒的sql MySQL 自带 slow log 的分析工具 mysqldumpslow. slow log 是 MySQL 根据 SQL 语句的执行时间设定,写入的一个文件,用于分析执行较慢的语句. 只要在 my.cnf 文件中配置好: log-slow-queries = [slow_quer

Oracle 复制表创建的sql语句

http://cache.baiducontent.com/c?m=9d78d513d99e01fc09b3c3690d67c0161343f0652ba1d4020ed08449e3732b42501195ac26520774d5d20c6116df3f4b99fa2235775d2feddd8eca5ddcc88f3579db6167204fc71605d36ea8c817639c37902db8f246fae9b0748eaed0d0dd5655d7500e7a85fb894d006390

oracle和java中的sql语句

在调试代码的时候遇到这样一个问题,程序运行到sql语句就抛invalid character异常,那我只好把sql语句拷出来,在oracle中执行一下,然而并没有什么错,这可难坏我了,这样都找不到错误,这到底是啥问题,摸不着头脑,一个老程序员提醒了我,在java中,sql语句的最后不能加分号,去掉之后可以正常执行了.虽然这是一个小问题,但我从来没注意过,以后就不会犯这低级错误了,哈哈.

带参方法的执行:普通方法的查询,可为空方法的查询。批量处理SQL语句。

普通方法的查询: @Override public List<Map<String, Object>> selectSpentAmount(Integer MAT_TYPE_, String DEPT_CODE_, Integer YEAR_, Map<String, Object> operator) { String sql = "select MAT_NO_, sum(AMOUNT_) as SPENT_AMOUNT_ from DM_MAT_MONTH

Oracle获取最近执行的SQL语句

注意:不是每次执行的语句都会记录(如果执行的语句是能在该表找到的则ORACLE不会再次记录,就是说本次执行的语句和上次或者说以前的语句一模一样则下面语句就查不出来的): select last_load_time, sql_text from v$sql where module not in ('jsenv.exe','w3wp.exe','SQL Developer') --and sql_text like '%"Extent1"."ENCOUNTERID"%