首页 > 数据库 >几个有用的oracle dba_hist_*查询语句

几个有用的oracle dba_hist_*查询语句

时间:2022-12-02 10:34:31浏览次数:47  
标签:dba SQL st hist DELTA oracle ID MINS CPU

耗CPU最多的10条语句 



select * from

(select

s.SQL_ID,

sum(s.CPU_TIME_DELTA),

sum(s.DISK_READS_DELTA),

count(*)

from DBA_HIST_SQLSTAT s

group by s.SQL_ID

order by sum(s.CPU_TIME_DELTA) desc

)

where rownum < 11

/


最近7天,指定时间段(8:00-16:00)最消耗CPU的10条语句



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 8 and 16

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

/


可以进一步关联DBA_HIST_SQLTEXT视图得到详细的SQL语句



select * from

(select

s.SQL_ID, s.SQL_TEXT

sum(s.CPU_TIME_DELTA),

sum(s.DISK_READS_DELTA),

count(*)

from DBA_HIST_SQLSTAT s, DBA_HIST_SNAPSHOT p, DBA_HIST_SQLTEXT t

where 1=1

and s.SNAP_ID = p.SNAP_ID

and s.SQL_ID = t.SQL_ID

and EXTRACT(HOUR FROM p.END_INTERVAL_TIME) between 8 and 16

and t.COMMAND_TYPE != 47 –- Exclude PL/SQL blocks from output

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

/


分析指定SQL语句各版本执行计划的资源消耗情况



select st.SQL_ID,

st.PLAN_HASH_VALUE,

sum(st.EXECUTIONS_DELTA) EXECUTIONS,

sum(st.ROWS_PROCESSED_DELTA) CROWS,

trunc(sum(st.CPU_TIME_DELTA)/1000000/60) CPU_MINS,

trunc(sum(st.ELAPSED_TIME_DELTA)/1000000/60) ELA_MINS

from DBA_HIST_SQLSTAT st

where st.SQL_ID in (‘&1′)

group by st.SQL_ID , st.PLAN_HASH_VALUE

order by st.SQL_ID, CPU_MINS;


分析对比SQL语句在不同执行计划中的执行情况



SELECT st2.SQL_ID,

st2.PLAN_HASH_VALUE,

st_long.PLAN_HASH_VALUE l_PLAN_HASH_VALUE,

st2.CPU_MINS,

st_long.CPU_MINS l_CPU_MINS,

st2.ELA_MINS,

st_long.ELA_MINS l_ELA_MINS,

st2.EXECUTIONS,

st_long.EXECUTIONS l_EXECUTIONS,

st2.CROWS,

st_long.CROWS l_CROWS,

st2.CPU_MINS_PER_ROW,

st_long.CPU_MINS_PER_ROW l_CPU_MINS_PER_ROW

FROM

(SELECT st.SQL_ID,

st.PLAN_HASH_VALUE,

SUM(st.EXECUTIONS_DELTA) EXECUTIONS,

SUM(st.ROWS_PROCESSED_DELTA) CROWS,

TRUNC(SUM(st.CPU_TIME_DELTA) /1000000/60) CPU_MINS ,

DECODE( SUM(st.ROWS_PROCESSED_DELTA), 0 , 0 , (SUM(st.CPU_TIME_DELTA)/1000000/60)/SUM(st.ROWS_PROCESSED_DELTA) ) CPU_MINS_PER_ROW ,

TRUNC(SUM(st.ELAPSED_TIME_DELTA) /1000000/60) ELA_MINS

FROM DBA_HIST_SQLSTAT st

WHERE 1 =1

AND ( st.CPU_TIME_DELTA !=0

OR st.ROWS_PROCESSED_DELTA !=0)

GROUP BY st.SQL_ID,

st.PLAN_HASH_VALUE

) st2,

(SELECT st.SQL_ID,

st.PLAN_HASH_VALUE,

SUM(st.EXECUTIONS_DELTA) EXECUTIONS,

SUM(st.ROWS_PROCESSED_DELTA) CROWS,

TRUNC(SUM(st.CPU_TIME_DELTA) /1000000/60) CPU_MINS ,

DECODE( SUM(st.ROWS_PROCESSED_DELTA), 0 , 0 , (SUM(st.CPU_TIME_DELTA)/1000000/60)/SUM(st.ROWS_PROCESSED_DELTA) ) CPU_MINS_PER_ROW ,

TRUNC(SUM(st.ELAPSED_TIME_DELTA) /1000000/60) ELA_MINS

FROM DBA_HIST_SQLSTAT st

WHERE 1 =1

AND ( st.CPU_TIME_DELTA !=0

OR st.ROWS_PROCESSED_DELTA !=0)

HAVING TRUNC(SUM(st.CPU_TIME_DELTA)/1000000/60) > 10

GROUP BY st.SQL_ID,

st.PLAN_HASH_VALUE

) st_long

WHERE 1 =1

AND st2.SQL_ID = st_long.SQL_ID

AND st_long.CPU_MINS_PER_ROW/DECODE(st2.CPU_MINS_PER_ROW,0,1,st2.CPU_MINS_PER_ROW) > 2

ORDER BY l_CPU_MINS DESC,

st2.SQL_ID,

st_long.CPU_MINS DESC,

st2.PLAN_HASH_VALUE;

标签:dba,SQL,st,hist,DELTA,oracle,ID,MINS,CPU
From: https://blog.51cto.com/u_14230175/5905574

相关文章

  • (转)什么是裸设备?Oracle为什么要选用裸设备?
    裸设备,也叫裸分区(原始分区),是一种没有经过格式化,不被Unix通过文件系统来读取的特殊字符设备。本文收集裸设备和Oracle问答20例。1.什么叫做裸设备?裸......
  • java往oracle存储过程中传递数组方法小结
    java往oracle存储过程中传递数组方法小结,下面是一个例子,比如存储过程中要接受一个数组,并且输出一个数组,则先注意数组在oracle中的定义方法如下:CRE......
  • EBS: Oracle XML Publisher 表清单
    --OracleXMLPublisher表清单SELECT*FROMXDO.XDO_CONCURRENT_REQUESTS_GTSELECT*FROMXDO.XDO_CONFIG_KEYS--KEY:PROPERTY_CODE--配置属性SELECT*FR......
  • Oracle 查询用户下表名,表列数,表行数,表大小的SQL
    最近想分析下数据库的信息,然后写了这个SQL.比较lowB一些. 因为Oracle的deferred_segment_creation参数的影响.很多表如果是0行,那么是不会创建extents存储信息.......
  • Oracle常用脚本
    经常忘记一些oracle语法,在此做一下记录吧,每逢遇到新的脚本,就记录在此。1.通过存储过程的方式,将图片插入blob字段,创建目录并授权createdirectory  D_FILEas'/home/......
  • Oracle19c静默安装
    硬件环境准备龙晰操作系统7.9(rhel内核)虚拟机内存18Gcpu至强银牌磁盘200G创建安装目录及数据目录mkdir-p/u01/app/oracle/product/19.0.0/dbhome_1mkdir-p/u02/......
  • Oracle开窗函数rank() over(partition by ... order by ... desc)
    原文地址:https://www.cnblogs.com/LoveShare/p/16408656.html1.创建表 --CreatetablecreatetableTEST(IDNUMBER(10)notnull,NAMEVARCHAR2(50),......
  • Oracle 11g RAC 修改controlfile 路径
    11.rac集群资源现状2[root@rac1~]#crsctlstatres-t3--------------------------------------------------------------------------------4NAME......
  • navicat连接oracle报错、闪退
    win764位系统安装了NavicatPremium12,运行连接oracle会一闪而过,退出程序,但是连接其他的数据库sql等是可以,因此百度了一下,查看什么原因。原因:oci.dll文件是有问题的,需要重......
  • oracle赋给用户dba权限
    赋给user1权限grantdbatouser1;撤销user1权限revokedbafromuser1; dba:拥有全部特权,是系统最高权限,只有DBA才可以创建数据库结构。resource:拥有Resource权限的......