通過Statspack我們可以很容易的確定Oracle數據庫的瓶頸所在,記錄數據庫性能狀態,也可以使遠程技術支持人員迅速了解你的數據庫運行狀況。因此了解和使用Statspack對於DBA來說至關重要。
整理分析結果
可以通過各種工具建立圖表,使我們收集的數據更直觀,更有說服力。
以下是我給一個客戶做的分析報告的實例。
1.物理讀寫IO操作:
觀察物理IO訪問,可以看出數據庫日常訪問的峰值及繁忙程度。
腳本:此腳本按時間生成統計數據(注:以下示例以8i為基礎,SQL腳本中引用的statistic#在不同版本代表的意義可能不同,對於9i等版本,你應該修改相應參數值)
SQL代碼
select
substr(to_char(snap_time,'yyyy-mm-ddHH24:MI:SS'),12),
(newreads.value-oldreads.value)reads,
(newwrites.value-oldwrites.value)writes
from
perfstat.stats$sysstatoldreads,
perfstat.stats$sysstatnewreads,
perfstat.stats$sysstatoldwrites,
perfstat.stats$sysstatnewwrites,
perfstat.stats$snapshotsn
where
newreads.snap_id=sn.snap_id
and
newwrites.snap_id=sn.snap_id
and
oldreads.snap_id=sn.snap_id-1
and
oldwrites.snap_id=sn.snap_id-1
and
oldreads.statistic#=40
and
newreads.statistic#=40
and
oldwrites.statistic#=41
and
newwrites.statistic#=41
and
(newreads.value-oldreads.value)>0
and
(newwrites.value-oldwrites.value)>0select
substr(to_char(snap_time,'yyyy-mm-ddHH24:MI:SS'),12),
(newreads.value-oldreads.value)reads,
(newwrites.value-oldwrites.value)writes
from
perfstat.stats$sysstatoldreads,
perfstat.stats$sysstatnewreads,
perfstat.stats$sysstatoldwrites,
perfstat.stats$sysstatnewwrites,
perfstat.stats$snapshotsn
where
newreads.snap_id=sn.snap_id
and
newwrites.snap_id=sn.snap_id
and
oldreads.snap_id=sn.snap_id-1
and
oldwrites.snap_id=sn.snap_id-1
and
oldreads.statistic#=40
and
newreads.statistic#=40
and
oldwrites.statistic#=41
and
newwrites.statistic#=41
and
(newreads.value-oldreads.value)>0
and
(newwrites.value-oldwrites.value)>0
/
圖表:
分析:
從趨勢圖中我們可以看出,數據庫每日讀操作較為平穩,數據量大約在4000左右。在下午2點到5點期
間比較繁忙。峰值達到150000左右。
數據庫寫操作變化也比較平穩,數據改變量在80000左右,凌晨一點半到早晨8點半左右數據庫訪問極少。
這是一個以寫為主的數據庫,我們需要更多注意的是寫競爭。
2.Buffer命中率
Sql代碼
select
substr(to_char(snap_time,'yyyy-mm-ddHH24:MI'),12),
round(100*(((a.value-e.value)+(b.value-f.value))-(c.value-g.value))/
((a.value-e.value)+(b.value-f.value)))
"BUFFERHITRATIO"
from
perfstat.stats$sysstata,
perfstat.stats$sysstatb,
perfstat.stats$sysstatc,
perfstat.stats$sysstatd,
perfstat.stats$sysstate,
perfstat.stats$sysstatf,
perfstat.stats$sysstatg,
perfstat.stats$snapshotsn
where
a.snap_id=sn.snap_id
and
b.snap_id=sn.snap_id
and
c.snap_id=sn.snap_id
and
d.snap_id=sn.snap_id
and
e.snap_id=sn.snap_id-1
and
f.snap_id=sn.snap_id-1
and
g.snap_id=sn.snap_id-1
and
a.statistic#=39
and
e.statistic#=39
and
b.statistic#=38
and
f.statistic#=38
and
c.statistic#=40
and
g.statistic#=40
and
d.statistic#=41select
substr(to_char(snap_time,'yyyy-mm-ddHH24:MI'),12),
round(100*(((a.value-e.value)+(b.value-f.value))-(c.value-g.value))/
((a.value-e.value)+(b.value-f.value)))
"BUFFERHITRATIO"
from
perfstat.stats$sysstata,
perfstat.stats$sysstatb,
perfstat.stats$sysstatc,
perfstat.stats$sysstatd,
perfstat.stats$sysstate,
perfstat.stats$sysstatf,
perfstat.stats$sysstatg,
perfstat.stats$snapshotsn
where
a.snap_id=sn.snap_id
and
b.snap_id=sn.snap_id
and
c.snap_id=sn.snap_id
and
d.snap_id=sn.snap_id
and
e.snap_id=sn.snap_id-1
and
f.snap_id=sn.snap_id-1
and
g.snap_id=sn.snap_id-1
and
a.statistic#=39
and
e.statistic#=39
and
b.statistic#=38
and
f.statistic#=38
and
c.statistic#=40
and
g.statistic#=40
and
d.statistic#=41
圖表:
分析:
Buffer(bufferhitratio)命中率是考察Oracle數據庫性能的重要指標,它代表在內存中找到需要數據的比
率,一般來說,如果該值小於90%,則可能說明數據庫存在大量代價昂貴的IO操作,數據庫需要調整。
我們數據庫的buffer命中率幾乎接近100%,最低值在95%左右,這個比率是比較優化的。
安裝statspack
SQL>connect/assysdbaSQL>@?/rdbms/admin/spcreate
卸載
SQL>connect/assysdba
SQL>@?/rdbms/admin/spdrop
/*
收集信息前把timed_statistics=true;
altersystemsettimed_statistics=true;
*/
收集信息
SQL>connectperfstat/perfstat
SQL>executestatspack.snap;
自動收集
SQL>connectperfstat/perfstat
SQL>@?/rdbms/admin/spauto
刪掉自動收集的job.
SQL>select*fromuser_jobs;SQL>execdbms_job.remove(JOB_ID)
/*
executestatspack.snap(i_snap_level=>10,i_modify_parameter=>'true');
Levels=5Additionaldata:SQLStatements
Levels=6Thislevelincludesallstatisticsgatheredinthelowerlevel(s).Levels=7segmentslevelstatistics
Levels=10Additionalstatistics:Childlatches
i_modify_parameter=>'true'/'false'決定是否保存level的值,下一次執行繼續使用
*/
產生報告
SQL>conectperfstat/perfstat
SQL>@?/rdbms/admin/spreport