TopSQL,計算某條sql的CPU time.
select aa.*,
(select sql_text from perfstat.top_sql_monitor where aa.hash_value = perfstat.top_sql_monitor.hash_value and rownum =1 and
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
) sql_text
,(select b.username from perfstat.top_sql_monitor, dba_users b where aa.hash_value = perfstat.top_sql_monitor.hash_value and rownum =1 and
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
and perfstat.top_sql_monitor.parsing_user_id = b.user_id
) parsing_user_id
from (
select hash_value, round(sum(cpu_time)/1000000,0) "cpu_time(s)"
, round(sum(total_cpu_time)/1000000,0) "total_cpu_time(s)"
--, round(sum(total_cpu_time)/1000000/15/60,0) "cpu_time_ps(s)"
, round(sum(total_cpu_time)/1000000/60/60,0) "cpu_time_ps(s)"
, round(sum(cpu_time)/sum(total_cpu_time),3) "percent_cpu_time(s)"
, round(sum(elapsed_time)/1000000,1) "elapsed_time(s)", sum(executions) executions, sum(buffer_gets) buffer_gets, sum(disk_reads) disk_reads from (select
s.snap_time,
s.hash_value,
decode(sign(cpu_time - lag(cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
cpu_time,
cpu_time - lag(cpu_time, 1) over(partition by hash_value order by s.snap_time )) as cpu_time,
decode(sign(total_cpu_time - lag(total_cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
total_cpu_time,
total_cpu_time - lag(total_cpu_time, 1) over(partition by hash_value order by s.snap_time )) as total_cpu_time,
decode(sign(s.executions - lag(executions, 1)
over(partition by hash_value order by s.snap_time )),
-1,
executions,
s.executions - lag(executions, 1) over(partition by hash_value order by s.snap_time)) as executions,
decode(sign(s.elapsed_time - lag(elapsed_time, 1)
over(partition by hash_value order by s.snap_time)),
-1,
elapsed_time,
s.elapsed_time - lag(elapsed_time, 1) over(partition by hash_value order by s.snap_time)) as elapsed_time,
decode(sign(s.buffer_gets - lag(buffer_gets, 1)
over(partition by hash_value order by s.snap_time )),
-1,
buffer_gets,
s.buffer_gets - lag(buffer_gets, 1) over(partition by hash_value order by s.snap_time)) as buffer_gets,
decode(sign(s.disk_reads - lag(disk_reads, 1)
over(partition by hash_value order by s.snap_time )),
-1,
disk_reads,
s.disk_reads - lag(disk_reads, 1) over(partition by hash_value order by s.snap_time )) as disk_reads,
decode(sign(s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )),
-1,
fetches,
s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )) as fetches,
decode(sign(s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )),
-1,
sorts,
s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )) as sorts
from perfstat.top_sql_monitor s
where
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
--and parsing_user_id = 97
) where executions is not null
group by hash_value
order by 2 desc ) aa where rownum <1000
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
) sql_text
,(select b.username from perfstat.top_sql_monitor, dba_users b where aa.hash_value = perfstat.top_sql_monitor.hash_value and rownum =1 and
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
and perfstat.top_sql_monitor.parsing_user_id = b.user_id
) parsing_user_id
from (
select hash_value, round(sum(cpu_time)/1000000,0) "cpu_time(s)"
, round(sum(total_cpu_time)/1000000,0) "total_cpu_time(s)"
--, round(sum(total_cpu_time)/1000000/15/60,0) "cpu_time_ps(s)"
, round(sum(total_cpu_time)/1000000/60/60,0) "cpu_time_ps(s)"
, round(sum(cpu_time)/sum(total_cpu_time),3) "percent_cpu_time(s)"
, round(sum(elapsed_time)/1000000,1) "elapsed_time(s)", sum(executions) executions, sum(buffer_gets) buffer_gets, sum(disk_reads) disk_reads from (select
s.snap_time,
s.hash_value,
decode(sign(cpu_time - lag(cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
cpu_time,
cpu_time - lag(cpu_time, 1) over(partition by hash_value order by s.snap_time )) as cpu_time,
decode(sign(total_cpu_time - lag(total_cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
total_cpu_time,
total_cpu_time - lag(total_cpu_time, 1) over(partition by hash_value order by s.snap_time )) as total_cpu_time,
decode(sign(s.executions - lag(executions, 1)
over(partition by hash_value order by s.snap_time )),
-1,
executions,
s.executions - lag(executions, 1) over(partition by hash_value order by s.snap_time)) as executions,
decode(sign(s.elapsed_time - lag(elapsed_time, 1)
over(partition by hash_value order by s.snap_time)),
-1,
elapsed_time,
s.elapsed_time - lag(elapsed_time, 1) over(partition by hash_value order by s.snap_time)) as elapsed_time,
decode(sign(s.buffer_gets - lag(buffer_gets, 1)
over(partition by hash_value order by s.snap_time )),
-1,
buffer_gets,
s.buffer_gets - lag(buffer_gets, 1) over(partition by hash_value order by s.snap_time)) as buffer_gets,
decode(sign(s.disk_reads - lag(disk_reads, 1)
over(partition by hash_value order by s.snap_time )),
-1,
disk_reads,
s.disk_reads - lag(disk_reads, 1) over(partition by hash_value order by s.snap_time )) as disk_reads,
decode(sign(s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )),
-1,
fetches,
s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )) as fetches,
decode(sign(s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )),
-1,
sorts,
s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )) as sorts
from perfstat.top_sql_monitor s
where
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
--and parsing_user_id = 97
) where executions is not null
group by hash_value
order by 2 desc ) aa where rownum <1000
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-745277/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 獲得消耗cpu較高的topsqlSQL
- 清除shared pool中某條sql的執行計劃SQL
- 批次殺執行某條sql的sessionSQLSession
- 某條SQL突然變慢的問題分析SQL
- 如何清除某條SQL在庫快取中的執行計劃SQL快取
- 某條sql的buffer gets 的歷史月度變化SQL
- DB CPU time% 的計算公式公式
- 一條主鍵索引SQL導致的CPU被打滿索引SQL
- 計算cpu速度的小程式 (轉)
- sql server 中刪除內容重複的某條記錄SQLServer
- PLSQL實現計算某數的平方SQL
- 詳述一條SQL引發的高CPU故障處理過程SQL
- SQL 有序計算SQL
- SQL 的後計算指令碼SQL指令碼
- 實現四則運算的一條sql語句SQL
- 計算兩條直線的交點
- 定位rac環境中某條sql執行時間過長SQL
- mac的cpu某段時間佔用很高Mac
- 如何計算字串某個字元出現的次數字串字元
- SQL 轉置計算SQL
- SQL Server日期計算SQLServer
- 什麼是計算機 cpu 的地址匯流排?計算機
- 計算機程式設計的24條法規 (轉)計算機程式設計
- 改進的sql計算n王后SQL
- Windows 平臺計算 CPU 總利用率Windows
- 計算機硬體的五大單元 & CPU的種類 & 計算機的執行流程計算機
- 計算某個範圍內的質數和的辦法
- sql去除某個欄位中的某個字串 replaceSQL字串
- SQL Server日期計算 (轉)SQLServer
- C#使用ManagementObjectSearcher獲取本計算機CPU,硬碟,記憶體條等相關裝置資訊C#Object計算機硬碟記憶體
- 【SQL】SQL中if條件的使用SQL
- 你的軟體按什麼賣?套數、CPU數、核數還是CPU的計算能力?
- 從計算機CPU設計談P\NP問題(0)計算機
- 從計算機CPU設計談P\NP問題(1)計算機
- 一條sql瞭解MYSQL的架構設計MySql架構
- 一條 sql 瞭解 MYSQL 的架構設計MySql架構
- 網易某業務線的計算資源資料治理實踐
- 985計算機院倒數第一某廢物的自述計算機