top sql(oracle)

简介: SET PAGESIZE 1000col sid for a6;col SPID for a10col 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; 

目录
相关文章
|
2月前
|
SQL 监控 Oracle
Oracle SQL性能优化全面指南
在数据库管理领域,Oracle SQL性能优化是确保数据库高效运行和数据查询速度的关键
|
2月前
|
SQL 存储 Oracle
Oracle数据库SQL语句详解与应用指南
在数字化时代,数据库已成为各类企业和组织不可或缺的核心组件。Oracle数据库作为业界领先的数据库管理系统之一,广泛应用于各种业务场景。掌握Oracle数据库的SQL语句是数据库管理员、开发人员及运维人员的基本技能。本文将详细介绍Oracle数据库SQL语句的基本概念、语法、应用及最佳实践。一、Or
86 3
|
2月前
|
SQL Oracle 关系型数据库
Oracle SQL:了解执行计划和性能调优
Oracle SQL:了解执行计划和性能调优
76 1
|
4月前
|
SQL 数据挖掘 大数据
如何在 SQL Server 中使用 `SELECT TOP`
【8月更文挑战第10天】
204 7
如何在 SQL Server 中使用 `SELECT TOP`
|
5月前
|
SQL Oracle 关系型数据库
|
5月前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
388 3
|
5月前
|
SQL 存储 Oracle
TDengine 3.3.2.0 发布:新增 UDT 及 Oracle、SQL Server 数据接入
**TDengine 3.3.2.0 发布摘要** - 开源与企业版均强化性能,提升WebSocket、stmt模式写入与查询效率,解决死锁,增强列显示。 - taos-explorer支持geometry和varbinary类型。 - 企业版引入UDT,允许自定义数据转换。 - 新增Oracle和SQL Server数据接入。 - 数据同步优化,支持压缩,提升元数据同步速度,错误信息细化,支持表名修改。 - 扩展跨平台支持,包括麒麟、Euler、Anolis OS等。
135 0
|
SQL Oracle 关系型数据库
Oracle SQL性能优化40条,值得收藏(一)
之前有发布一些Mysql的性能优化方法,有些小伙伴想了解一下Oracle的性能优化有哪些,特地去找了一些比较全和实用的文章,这篇就是其中一篇。对Oracle性能优化感兴趣的不妨收藏一些,以备不时之需。(部分内容存在错别字和技术性错误,有改动)
Oracle SQL性能优化40条,值得收藏(一)
|
SQL Oracle 关系型数据库
Oracle SQL性能优化40条,值得收藏(五)
之前有发布一些Mysql的性能优化方法,有些小伙伴想了解一下Oracle的性能优化有哪些,特地去找了一些比较全和实用的文章,这篇就是其中一篇。对Oracle性能优化感兴趣的不妨收藏一些,以备不时之需。(部分内容存在错别字和技术性错误,有改动)
Oracle SQL性能优化40条,值得收藏(五)
|
SQL Oracle 关系型数据库
Oracle SQL性能优化40条,值得收藏(四)
之前有发布一些Mysql的性能优化方法,有些小伙伴想了解一下Oracle的性能优化有哪些,特地去找了一些比较全和实用的文章,这篇就是其中一篇。对Oracle性能优化感兴趣的不妨收藏一些,以备不时之需。(部分内容存在错别字和技术性错误,有改动)
Oracle SQL性能优化40条,值得收藏(四)

推荐镜像

更多