【脚本内容】
在发现Oracle进程大量消耗CPU后,可以通过如下SQL获取服务器进程内正在执行的语句。
显示按CPU统计的顶级SQL。
select substr(sql_text,1,500) "SQL",
(cpu_time/1000000) "CPU_Seconds",
disk_reads "Disk_Reads",
buffer_gets "Buffer_Gets",
executions "Executions",
case when rows_processed = 0 then null
else round((buffer_gets/nvl(replace(rows_processed,0,1),1)))
end "Buffer_gets/rows_proc",
round((buffer_gets/nvl(replace(executions,0,1),1))) "Buffer_gets/executions",
(elapsed_time/1000000) "Elapsed_Seconds",module "Module"
from gv$sql s
order by cpu_time desc nulls last;
【截图如下】