开发者社区> jan1990> 正文

top sql(oracle)

简介: SET PAGESIZE 1000 col sid for a6; col SPID for a10 col SERIAL# for a8; col SCHEMANAME for a15; col OSUSER for a15; col username for a15; col MACHINE...
+关注继续查看

SET PAGESIZE 1000

col sid for a6;
col SPID for a10
col SERIAL# for a8;
col SCHEMANAME for a15;
col OSUSER for a15;
col username for a15;
col MACHINE for a18;
col TERMINAL for a15;
col LOGON_TIME for a21
col "已执行时间_秒" for a12
col EVENT for a30;
col SQL_TEXT for a80;
col FIRST_LOAD_TIME for a20;
col LAST_LOAD_TIME for a20;
col LAST_ACTIVE_TIME for a20;
col SQL_ID FOR A15;

PROMPT 
prompt ==> 当前 TOP CPU 
SELECT * FROM (
SELECT * FROM (
SELECT
       ROUND(CPU_TIME/1000000/decode(EXECUTIONS+USERS_EXECUTING,0,1,EXECUTIONS+USERS_EXECUTING),3) as AVG_CPU_TIME_S, 
       B.EXECUTIONS,
       USERS_EXECUTING,       
       A.SID,
       A.SERIAL#,
       A.STATUS,
       A.MACHINE,      
       A.OSUSER,
       A.USERNAME,
       TO_CHAR(A.LOGON_TIME,'yyyy-mm-dd hh24:mi:ss') AS LOGON_DATE,
       TRUNC((SYSDATE - A.LOGON_TIME) * 24 * 60*60) AS LOGON_TIME_S,
       A.LAST_CALL_ET AS LAST_CALL_ET_S,      
       A.EVENT,
       A.SQL_ID,
       SUBSTR(B.SQL_TEXT,0,100) AS SQL_TEXT
  FROM V$SESSION A, V$SQL B
 WHERE USERS_EXECUTING >= 1 
   AND USERNAME NOT IN ('SYS')
   AND A.SQL_ADDRESS = B.ADDRESS
   AND A.USERNAME IS NOT NULL AND A.SQL_ID=B.SQL_ID AND A.SQL_CHILD_NUMBER=B.CHILD_NUMBER 
 ) WHERE STATUS='ACTIVE' ORDER BY  AVG_CPU_TIME_S DESC 
 ) WHERE ROWNUM<=10;
 


PROMPT 
prompt ==> 当前 TOP IO
SELECT * FROM (
SELECT * FROM (
SELECT ROUND ((B.PHYSICAL_READ_BYTES + B.PHYSICAL_WRITE_BYTES) / DECODE (B.EXECUTIONS+USERS_EXECUTING, 0, 1, B.EXECUTIONS+USERS_EXECUTING)/ 1024/ 1024,2) AS AVG_IO_SIZE_MB,
       B.EXECUTIONS,
       USERS_EXECUTING,       
       A.SID,
       A.SERIAL#,
       A.STATUS,
       A.MACHINE,      
       A.OSUSER,
       A.USERNAME,
       TO_CHAR(A.LOGON_TIME,'yyyy-mm-dd hh24:mi:ss') AS LOGON_DATE,
       TRUNC((SYSDATE - A.LOGON_TIME) * 24 * 60*60) AS LOGON_TIME_S,
       A.LAST_CALL_ET AS LAST_CALL_ET_S,      
       A.EVENT,
       A.SQL_ID,
       SUBSTR(B.SQL_TEXT,0,100) AS SQL_TEXT
  FROM V$SESSION A, V$SQL B
 WHERE USERS_EXECUTING >= 1 
   AND USERNAME NOT IN ('SYS')
   AND A.SQL_ADDRESS = B.ADDRESS
   AND A.USERNAME IS NOT NULL AND A.SQL_ID=B.SQL_ID AND A.SQL_CHILD_NUMBER=B.CHILD_NUMBER 
 ) WHERE STATUS='ACTIVE' ORDER BY  AVG_IO_SIZE_MB DESC 
 ) WHERE ROWNUM<=10;

 
PROMPT 
prompt ==> 当前 TOP BUFFER_GETS
SELECT * FROM (
SELECT * FROM (
SELECT ROUND(B.BUFFER_GETS/(DECODE (B.EXECUTIONS+USERS_EXECUTING, 0, 1, B.EXECUTIONS+USERS_EXECUTING)),0) AS AVG_BUFFER_GETS,
       B.EXECUTIONS,
       USERS_EXECUTING,       
       A.SID,
       A.SERIAL#,
       A.STATUS,
       A.MACHINE,
       A.OSUSER,
       A.USERNAME,
       TO_CHAR(A.LOGON_TIME,'yyyy-mm-dd hh24:mi:ss') AS LOGON_DATE,
       TRUNC((SYSDATE - A.LOGON_TIME) * 24 * 60*60) AS LOGON_TIME_S,
       A.LAST_CALL_ET AS LAST_CALL_ET_S,      
       A.EVENT,
       A.SQL_ID,
       SUBSTR(B.SQL_TEXT,0,100) AS SQL_TEXT
  FROM V$SESSION A, V$SQL B
 WHERE USERS_EXECUTING >= 1 
   AND USERNAME NOT IN ('SYS')
   AND A.SQL_ADDRESS = B.ADDRESS
   AND A.USERNAME IS NOT NULL AND A.SQL_ID=B.SQL_ID AND A.SQL_CHILD_NUMBER=B.CHILD_NUMBER 
 ) WHERE STATUS='ACTIVE' ORDER BY  AVG_BUFFER_GETS DESC 
 ) WHERE ROWNUM<=10;
 
 
PROMPT 
prompt ==> FULL TABLE SCAN
SELECT * FROM (
SELECT * FROM (
SELECT ROUND (B.PHYSICAL_READ_BYTES  / DECODE (B.EXECUTIONS+USERS_EXECUTING, 0, 1, B.EXECUTIONS+USERS_EXECUTING)/ 1024/ 1024,2) AS AVG_PHYSICAL_READ_BYTES_MB,
       B.EXECUTIONS,
       USERS_EXECUTING,
       A.SID,
       A.SERIAL#,
       A.STATUS,
       A.MACHINE,      
       A.OSUSER,
       A.USERNAME,
       TO_CHAR(A.LOGON_TIME,'yyyy-mm-dd hh24:mi:ss') AS LOGON_DATE,
       TRUNC((SYSDATE - A.LOGON_TIME) * 24 * 60*60) AS LOGON_TIME_S,
       A.LAST_CALL_ET AS LAST_CALL_ET_S,      
       A.EVENT,
       A.SQL_ID,
       SUBSTR(B.SQL_TEXT,0,100) AS SQL_TEXT
  from v$session a, v$sql b
 where USERS_EXECUTING >= 1 
   and username not in ('SYS')
   and a.last_call_et / 60 >= 0
   and a.sql_address = b.address
   and a.username is not null AND A.SQL_ID=B.SQL_ID and A.SQL_CHILD_NUMBER=B.CHILD_NUMBER 
   AND (A.SQL_ID,PLAN_HASH_VALUE)IN (SELECT DISTINCT SQL_ID,PLAN_HASH_VALUE FROM V$SQL_PLAN WHERE OPERATION='TABLE ACCESS' AND OPTIONS ='FULL')
 ) WHERE  STATUS='ACTIVE' ORDER BY  AVG_PHYSICAL_READ_BYTES_MB DESC 
 ) WHERE ROWNUM<=10;
 
 
 
 
 
 
PROMPT ==>>>找出一小时内消耗IO的TOP SQL 
SELECT ash.sql_id,count(*)
 FROM V$ACTIVE_SESSION_HISTORY ASH,V$EVENT_NAME EVT
WHERE ash.sample_time > sysdate -1/24
   AND ash.session_state = 'WAITING'
   AND ash.event_id = evt.event_id
   AND evt.wait_class = 'USER I/O'
GROUP BY ash.sql_id
 ORDER BY count(*) desc;




PROMPT ==>>>找出一小时个内消耗CPU的TOP session 
select * from 
(
SELECT session_id,count(*)
 FROM V$ACTIVE_SESSION_HISTORY
WHERE session_state = 'ON CPU'
   AND sample_time > sysdate -1/24
GROUP BY session_id
ORDER BY count(*) desc
) where rownum <21;



prompt ==>最近7天top cpu 
select *
  from (select s.SQL_ID,
               sum(s.CPU_TIME_DELTA),
               sum(s.DISK_READS_DELTA),
               count(*)
          from DBA_HIST_SQLSTAT s, DBA_HIST_SNAPSHOT p
         where 1 = 1
           and s.SNAP_ID = p.SNAP_ID
           and EXTRACT(HOUR FROM p.END_INTERVAL_TIME) between 9 and 17
           and p.END_INTERVAL_TIME between SYSDATE - 7 and SYSDATE
         group by s.SQL_ID
         order by sum(s.CPU_TIME_DELTA) desc) 
 where rownum < 11 
 
 
 
 
prompt ===>awr 中的top sql
select * from 
(
select sql_id,
       "CPU + CPU Wait",
       "User I/O",
       "Application",
       "Network",
       "Concurrency",
       "Configuration",
       "Other",
       "System I/O",
       "Commit",
       "Queueing",
       "Administrative",
       "Scheduler",
       ("CPU + CPU Wait" + "User I/O" + "Application" + "Network" +
       "Concurrency" + "Configuration" + "Other" + "System I/O" + "Commit" +
       "Queueing" + "Administrative" + "Scheduler") TOTAL
  from (select ash.sql_id,
               sum(decode(ash.session_state, 'ON CPU', 1, 0)) "CPU + CPU Wait",
               sum(decode(ash.WAIT_CLASS, 'User I/O', 1, 0)) "User I/O",
               sum(decode(ash.WAIT_CLASS, 'Application', 1, 0)) "Application",
               sum(decode(ash.WAIT_CLASS, 'Network', 1, 0)) "Network",
               sum(decode(ash.WAIT_CLASS, 'Concurrency', 1, 0)) "Concurrency",
               sum(decode(ash.WAIT_CLASS, 'Configuration', 1, 0)) "Configuration",
               sum(decode(ash.WAIT_CLASS, 'Other', 1, 0)) "Other",
               sum(decode(ash.WAIT_CLASS, 'System I/O', 1, 0)) "System I/O",
               sum(decode(ash.WAIT_CLASS, 'Commit', 1, 0)) "Commit",
               sum(decode(ash.WAIT_CLASS, 'Queueing', 1, 0)) "Queueing",
               sum(decode(ash.WAIT_CLASS, 'Administrative', 1, 0)) "Administrative",
               sum(decode(ash.WAIT_CLASS, 'Scheduler', 1, 0)) "Scheduler"
          from V$ACTIVE_SESSION_HISTORY ash
         where sample_time > sysdate - 30 / 24 / 60
         group by ash.sql_id)
 where sql_id is not null
 order by total desc 
 )
 where rownum < 10; 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
如何设置阿里云服务器安全组?阿里云安全组规则详细解说
阿里云安全组设置详细图文教程(收藏起来) 阿里云服务器安全组设置规则分享,阿里云服务器安全组如何放行端口设置教程。阿里云会要求客户设置安全组,如果不设置,阿里云会指定默认的安全组。那么,这个安全组是什么呢?顾名思义,就是为了服务器安全设置的。安全组其实就是一个虚拟的防火墙,可以让用户从端口、IP的维度来筛选对应服务器的访问者,从而形成一个云上的安全域。
18580 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
27723 0
阿里云服务器安全组设置内网互通的方法
虽然0.0.0.0/0使用非常方便,但是发现很多同学使用它来做内网互通,这是有安全风险的,实例有可能会在经典网络被内网IP访问到。下面介绍一下四种安全的内网互联设置方法。 购买前请先:领取阿里云幸运券,有很多优惠,可到下文中领取。
21933 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
19980 0
阿里云服务器ECS登录用户名是什么?系统不同默认账号也不同
阿里云服务器Windows系统默认用户名administrator,Linux镜像服务器用户名root
15287 0
腾讯云服务器 设置ngxin + fastdfs +tomcat 开机自启动
在tomcat中新建一个可以启动的 .sh 脚本文件 /usr/local/tomcat7/bin/ export JAVA_HOME=/usr/local/java/jdk7 export PATH=$JAVA_HOME/bin/:$PATH export CLASSPATH=.
14852 0
使用OpenApi弹性释放和设置云服务器ECS释放
云服务器ECS的一个重要特性就是按需创建资源。您可以在业务高峰期按需弹性的自定义规则进行资源创建,在完成业务计算的时候释放资源。本篇将提供几个Tips帮助您更加容易和自动化的完成云服务器的释放和弹性设置。
20878 0
+关注
43
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
JS零基础入门教程(上册)
立即下载
性能优化方法论
立即下载
手把手学习日志服务SLS,云启实验室实战指南
立即下载