從DBA_HIST_SQLSTAT檢視中查詢過去時段最佔用資源的會話
超過閥值的sql語句會在awr中儲存一段時間(預設是7天),可以透過dba_hist_sqlstat檢視查詢。
1.查詢檢視dba_hist_sqlstat
select snap_id, disk_reads_delta reads_delta,
executions_delta exec_delta, disk_reads_delta /decode
(executions_delta, 0, 1,executions_delta) rds_exec_ratio,
sql_id
from dba_hist_sqlstat
where disk_reads_delta > 100000
order by disk_reads_delta desc;
snap_id reads_delta exec_delta rds_exec_ratio sql_id
39 511106 1 511106 8h1qaqha580hh
29 216898 3 72299.33 d5bcqvumxr4y4
2.根據sql_id,在dba_hist_sqltext中檢視相關sql語句
select command_type,sql_text
from dba_hist_sqltext
where sql_id='d5bcqvumxr4y4';
command_type sql_text
3 select count(id) from bom
注:command_type=3表示這是select命令,完整的command_type可以select * from audit_actions;
3.檢視之前命令的執行計劃
select * from table(dbms_xplan.display_awr('8h1qaqha580hh'));
========================================================================
補充幾個有用的oracle dba_hist_*查詢語句 :
1.耗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;
2.最近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;
3.可以進一步關聯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
4.分析指定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;
5.分析對比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;
1.查詢檢視dba_hist_sqlstat
select snap_id, disk_reads_delta reads_delta,
executions_delta exec_delta, disk_reads_delta /decode
(executions_delta, 0, 1,executions_delta) rds_exec_ratio,
sql_id
from dba_hist_sqlstat
where disk_reads_delta > 100000
order by disk_reads_delta desc;
snap_id reads_delta exec_delta rds_exec_ratio sql_id
39 511106 1 511106 8h1qaqha580hh
29 216898 3 72299.33 d5bcqvumxr4y4
2.根據sql_id,在dba_hist_sqltext中檢視相關sql語句
select command_type,sql_text
from dba_hist_sqltext
where sql_id='d5bcqvumxr4y4';
command_type sql_text
3 select count(id) from bom
注:command_type=3表示這是select命令,完整的command_type可以select * from audit_actions;
3.檢視之前命令的執行計劃
select * from table(dbms_xplan.display_awr('8h1qaqha580hh'));
========================================================================
補充幾個有用的oracle dba_hist_*查詢語句 :
1.耗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;
2.最近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;
3.可以進一步關聯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
4.分析指定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;
5.分析對比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;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2138943/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 從V$SESSMETRIC檢視中找出當前最佔用資源的會話SSM會話
- 檢視資料庫最佔資源或記憶體的查詢SQL資料庫記憶體SQL
- oracle 查詢什麼sql佔用臨時段OracleSQL
- Oracle 查詢佔用臨時表空間大的歷史會話和SQLOracle會話SQL
- ubuntu檢視系統資源佔用Ubuntu
- 查詢佔用資源高的JAVA程式碼Java
- 查詢某佔用資源較多的SQLSQL
- 快速清除佔用資源大的會話(from eygle)會話
- 從oracle v$version檢視中查詢os的資訊Oracle
- 利用jstack檢視程式資源佔用JS
- v$session/v$process檢視涉及的相關會話資訊的查詢Session會話
- 實時查詢最耗CPU資源的SQL語句SQL
- 在AIX下查詢佔用資源較多的程式AI
- 資料庫中會話休眠一段時間資料庫會話
- 查詢最佔資源、CPU、記憶體、和執行最長的SQL語句記憶體SQL
- 查詢過去一段時間內某條sql使用的臨時表空間大小SQL
- 儲存過程中查詢資料字典檢視(v$或dba)儲存過程
- RAC:在子查詢使用gv$檢視,有時查詢不出資料
- 檢視系統中各種等待時間佔用的資料庫時間比例資料庫
- 【DBA】DBA_HIST_SQLSTAT檢視用途SQL
- 資料庫的查詢與檢視資料庫
- 【Oracle】如何查詢檢視時使用索引Oracle索引
- 查詢UNIX/LINUX 下的佔用CPU資源的SQL語句LinuxSQL
- 會話和鎖資訊查詢檢視 | 全方位認識 sys 系統庫會話
- EBS中通過查詢 dba_source 檢視pkg 的版本號
- 查詢某時間段的統計資料
- OEM模組審計查詢語句佔用較大資源
- JPA時間段查詢
- MySQL查詢時間段MySql
- SQL時間段查詢SQL
- Oracle阻塞會話查詢Oracle會話
- 會話及物件查詢會話物件
- 檢視ELF中資料段哪些變數佔用空間變數
- 透過DMV查詢CPU時間最長的語句和查詢計劃
- 【會話】V$SESSION檢視會話Session
- MySQL查詢中Sending data佔用大量時間的問題處理MySql
- 檢視 Laravel 查詢資料語句Laravel
- user_source檢視使用&&查詢包和過程中的特定內容