网站首页 > 技术文章 正文
背景
在我们维护数据库库过程中,经常会碰到数据库调优的问题。而cpu利用率高是我们最常见的一个问题,而找出哪些session和和SQL语句在消耗最多的CPU,是我们经常面对的一个课题。本文分享一下在ORACLE中如何找出消耗CPU最多的SQL语句。
解决方案
Oracle 中的前 10 个 CPU 消耗会话
col program form a30 heading "Program"
col CPUMins form 99990 heading "CPU in Mins"
select rownum as rank, a.*
from (
SELECT v.sid,sess.Serial# ,program, v.value / (100 * 60) CPUMins
FROM v$statname s , v$sesstat v, v$session sess
WHERE s.name = 'CPU used by this session'
and sess.sid = v.sid
and v.statistic#=s.statistic#
and v.value>0
ORDER BY v.value DESC) a
where rownum < 11;
最近 10 分钟内 CPU 消耗最高的会话
col program form a30 heading "Program"
col CPUMins form 99990 heading "CPU in Mins"
select rownum as rank, a.*
from (
SELECT v.sid,sess.Serial# ,program, v.value / (100 * 60) CPUMins
FROM v$statname s , v$sesstat v, v$session sess
WHERE s.name = 'CPU used by this session'
and sess.sid = v.sid
and v.statistic#=s.statistic#
and v.value>0
ORDER BY v.value DESC) a
where rownum < 11;
在 Oracle 中消耗更多的 CPU的SQL id
col program form a30 heading "Program"
col cpu_usage_sec form 99990 heading "CPU in Seconds"
col MODULE for a18
col OSUSER for a10
col USERNAME for a15
col OSPID for a06 heading "OS PID"
col SID for 99999
col SERIAL# for 999999
col SQL_ID for a15
select * from (
select p.spid "ospid",
(se.SID),ss.serial#,ss.SQL_ID,ss.username,substr(ss.program,1,30) "program",
ss.module,ss.osuser,ss.MACHINE,ss.status,
se.VALUE/100 cpu_usage_sec
from v$session ss,v$sesstat se,
v$statname sn,v$process p
where
se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
and ss.username !='SYS'
and ss.status='ACTIVE'
and ss.username is not null
and ss.paddr=p.addr and value > 0
order by se.VALUE desc);
在 Oracle 中最消耗 CPU的SQL 文本
col cpu_usage_sec form 99990 heading "CPU in Seconds"
select * from (
select
(se.SID),substr(q.sql_text,80),ss.module,ss.status,se.VALUE/100 cpu_usage_sec
from v$session ss,v$sesstat se,
v$statname sn, v$process p, v$sql q
where
se.STATISTIC# = sn.STATISTIC#
AND ss.sql_address = q.address
AND ss.sql_hash_value = q.hash_value
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
and ss.username !='SYS'
and ss.status='ACTIVE'
and ss.username is not null
and ss.paddr=p.addr and value > 0
order by se.VALUE desc);
猜你喜欢
- 2025-09-01 新增支持Win11 Arm,甲骨文开源虚拟机VirtualBox 7.2发布
- 2025-09-01 核心库CPU飙到99%了!我发现很多DBA都不会看日志……
- 2024-11-07 使用Sysbench测试统信UOS或麒麟KYLINOS的CPU性能
- 2024-11-07 Flink oracle cdc - Oracle Logminer
- 2024-11-07 安全与优化并重 甲骨文SPARC M7处理器解析
- 2024-11-07 AMD R7 4750G在java开发中的日常体验
- 2024-11-07 CPU百分百?别慌,教你迅速排查的三种姿势
- 2024-11-07 Oracle正式发布MySQL HeatWave Lakehouse
- 2024-11-07 VMWare向AMD处理器开刀:你核心多,就要多缴费
- 2024-11-07 作为一个DBA,怎么去做日常巡检--检查数据库cpu、I/O、内存性能
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- oracle面试 (55)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)