oracle實用sql(11)--收集一週各時段的load profile
工作中需要對近一週每小時的db time,db cpu,logical read,physical read,transactions等資訊做成EXCEL圖表的形式,如果這些資料從awr報告中一個一個產生來收集就有些浪費時間了.
可以透過以下查詢,直接獲取資料庫各例項中按預設快照間隔的load profile,然後將查詢結果貼上到EXCEL中來形成圖表。
select f.instance_number,
f.stat_name,
to_char(f.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') b_time,
to_char(g.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') e_time,
(g.value - f.value) / 1000000 value_sum,
EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME) elapsed_second,
(g.value - f.value) / 1000000 /
(EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME)) value_per_sec
from (select a.instance_number,
a.snap_id b_snap_id,
lead(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYS_TIME_MODEL a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('DB time', 'DB CPU')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) f,
(select a.instance_number,
lag(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) b_snap_id,
a.snap_id e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYS_TIME_MODEL a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('DB time', 'DB CPU')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) g
where g.e_snap_id != 0
and f.b_snap_id != 0
and f.instance_number = g.instance_number
and f.stat_name = g.stat_name
and f.b_snap_id = g.b_snap_id
and f.e_snap_id = g.e_snap_id
union all
select f.instance_number,
f.stat_name,
to_char(f.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') b_time,
to_char(g.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') e_time,
(g.value - f.value) value_sum,
EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME) elapsed_second,
(g.value - f.value) /
(EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME)) value_per_sec
from (select a.instance_number,
a.snap_id b_snap_id,
lead(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYSSTAT a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('redo size',
'session logical reads',
'db block changes',
'physical reads',
'physical writes',
'user calls',
'parse count (total)',
'parse count (hard)',
'sorts (memory)',
'logons cumulative',
'execute count',
'user commits',
'user rollbacks')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) f,
(select a.instance_number,
lag(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) b_snap_id,
a.snap_id e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYSSTAT a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('redo size',
'session logical reads',
'db block changes',
'physical reads',
'physical writes',
'user calls',
'parse count (total)',
'parse count (hard)',
'sorts (memory)',
'logons cumulative',
'execute count',
'user commits',
'user rollbacks')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) g
where g.e_snap_id != 0
and f.b_snap_id != 0
and f.instance_number = g.instance_number
and f.stat_name = g.stat_name
and f.b_snap_id = g.b_snap_id
and f.e_snap_id = g.e_snap_id
order by 1, 2, 3;
可以透過以下查詢,直接獲取資料庫各例項中按預設快照間隔的load profile,然後將查詢結果貼上到EXCEL中來形成圖表。
select f.instance_number,
f.stat_name,
to_char(f.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') b_time,
to_char(g.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') e_time,
(g.value - f.value) / 1000000 value_sum,
EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME) elapsed_second,
(g.value - f.value) / 1000000 /
(EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME)) value_per_sec
from (select a.instance_number,
a.snap_id b_snap_id,
lead(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYS_TIME_MODEL a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('DB time', 'DB CPU')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) f,
(select a.instance_number,
lag(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) b_snap_id,
a.snap_id e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYS_TIME_MODEL a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('DB time', 'DB CPU')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) g
where g.e_snap_id != 0
and f.b_snap_id != 0
and f.instance_number = g.instance_number
and f.stat_name = g.stat_name
and f.b_snap_id = g.b_snap_id
and f.e_snap_id = g.e_snap_id
union all
select f.instance_number,
f.stat_name,
to_char(f.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') b_time,
to_char(g.END_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss') e_time,
(g.value - f.value) value_sum,
EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME) elapsed_second,
(g.value - f.value) /
(EXTRACT(DAY FROM g.end_interval_time - f.END_INTERVAL_TIME) * 86400 +
EXTRACT(HOUR FROM g.end_interval_time - f.END_INTERVAL_TIME) * 3600 +
EXTRACT(MINUTE FROM g.end_interval_time - f.END_INTERVAL_TIME) * 60 +
EXTRACT(SECOND FROM g.end_interval_time - f.END_INTERVAL_TIME)) value_per_sec
from (select a.instance_number,
a.snap_id b_snap_id,
lead(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYSSTAT a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('redo size',
'session logical reads',
'db block changes',
'physical reads',
'physical writes',
'user calls',
'parse count (total)',
'parse count (hard)',
'sorts (memory)',
'logons cumulative',
'execute count',
'user commits',
'user rollbacks')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) f,
(select a.instance_number,
lag(a.snap_id, 1, 0) over(partition by a.instance_number, stat_name order by a.snap_id) b_snap_id,
a.snap_id e_snap_id,
a.stat_name,
a.value,
b.end_interval_time
from DBA_HIST_SYSSTAT a, dba_hist_snapshot b
where a.snap_id = b.snap_id
and a.instance_number = b.instance_number
and a.stat_name in ('redo size',
'session logical reads',
'db block changes',
'physical reads',
'physical writes',
'user calls',
'parse count (total)',
'parse count (hard)',
'sorts (memory)',
'logons cumulative',
'execute count',
'user commits',
'user rollbacks')
and b.begin_interval_time >= trunc(sysdate - 7)
and b.begin_interval_time <= trunc(sysdate)) g
where g.e_snap_id != 0
and f.b_snap_id != 0
and f.instance_number = g.instance_number
and f.stat_name = g.stat_name
and f.b_snap_id = g.b_snap_id
and f.e_snap_id = g.e_snap_id
order by 1, 2, 3;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-2123382/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何解讀Oracle的LOAD PROFILEOracle
- oracle 查詢什麼sql佔用臨時段OracleSQL
- ORACLE SQL PROFILE使用OracleSQL
- Oracle利用coe_load_sql_profile指令碼繫結執行計劃OracleSQL指令碼
- oracle實用sql(10)--用statspack收集備庫效能資料OracleSQL
- angular 實現一週選擇時間段外掛Angular
- sql_profile的使用(一)SQL
- oracle之profile的應用Oracle
- oracle之 profile的應用Oracle
- SQL Profile 實驗03SQL
- SQL Profile 實驗02SQL
- SQL Profile 實驗01SQL
- Oracle11g使用sql_monitor實時監控sqlOracleSQL
- oracle11g增加profileOracle
- 怎麼估算一段時間裡,幾條SQL所佔用的時間SQL
- Oracle優化案例-view merge與coe_load_sql_profile固定執行計劃(十五)Oracle優化ViewSQL
- 一段常用的Page_Load事件事件
- oracle 11g增加業務profileOracle
- Spring Bean各階段生命週期的介紹SpringBean
- 【SQL Profile】coe_xfr_sql_profile.sql內容SQL
- sql profile的使用SQL
- Oracle SQL Profile固定執行計劃的方法OracleSQL
- sql profileSQL
- Oracle11DATA GUARD實時應用加實時查詢功能Oracle
- oracle 通過sql profile為sql語句加hintOracleSQL
- SQL Profile(第一篇)SQL
- oracle臨時段Oracle
- sql load的一點小總結SQL
- 使用sql profile實現outline的功能SQL
- Oracle運維指令碼-檢視DB各時間段健康狀況Oracle運維指令碼
- SQL時間段查詢SQL
- SQL優化--用各種hints優化一條SQLSQL優化
- sql profile使用SQL
- 用Axure實現對時間段的篩選
- Oracle 11g 建立臨時window時間視窗 收集統計資訊Oracle
- 效能下降的不定時炸彈_過舊的sql_profileSQL
- Oracle profile的使用Oracle
- oracle實用sql(12)--查詢資料是否在某個使用者下各個表的各個列OracleSQL