通過Statspack我們可以很容易的確定Oracle數據庫的瓶頸所在記錄數據庫性能狀態也可以使遠程技術支持人員迅速了解你的數據庫運行狀況因此了解和使用Statspack對於DBA來說至關重要
整理分析結果
可以通過各種工具建立圖表使我們收集的數據更直觀更有說服力
以下是我給一個客戶做的分析報告的實例
.物理讀寫IO操作
觀察物理IO訪問可以看出數據庫日常訪問的峰值及繁忙程度
腳本此腳本按時間生成統計數據(注:以下示例以i為基礎SQL腳本中引用的statistic#在不同版本代表的意義可能不同對於i等版本你應該修改相應參數值)
SQL代碼
select
substr(to_char(snap_timeyyyymmddHH:MI:SS))
(newreadsvalueoldreadsvalue)reads
(newwritesvalueoldwritesvalue)writes
from
perfstatstats$sysstatoldreads
perfstatstats$sysstatnewreads
perfstatstats$sysstatoldwrites
perfstatstats$sysstatnewwrites
perfstatstats$snapshotsn
where
newreadssnap_id=snsnap_id
and
newwritessnap_id=snsnap_id
and
oldreadssnap_id=snsnap_id
and
oldwritessnap_id=snsnap_id
and
oldreadsstatistic#=
and
newreadsstatistic#=
and
oldwritesstatistic#=
and
newwritesstatistic#=
and
(newreadsvalueoldreadsvalue)>
and
(newwritesvalueoldwritesvalue)>
select
substr(to_char(snap_timeyyyymmddHH:MI:SS))
(newreadsvalueoldreadsvalue)reads
(newwritesvalueoldwritesvalue)writes
from
perfstatstats$sysstatoldreads
perfstatstats$sysstatnewreads
perfstatstats$sysstatoldwrites
perfstatstats$sysstatnewwrites
perfstatstats$snapshotsn
where
newreadssnap_id=snsnap_id
and
newwritessnap_id=snsnap_id
and
oldreadssnap_id=snsnap_id
and
oldwritessnap_id=snsnap_id
and
oldreadsstatistic#=
and
newreadsstatistic#=
and
oldwritesstatistic#=
and
newwritesstatistic#=
and
(newreadsvalueoldreadsvalue)>
and
(newwritesvalueoldwritesvalue)>
/
圖表
)thisstylewidth=; border= twffan=done>
分析
從趨勢圖中我們可以看出數據庫每日讀操作較為平穩數據量大約在左右在下午點到點期
間比較繁忙峰值達到左右
數據庫寫操作變化也比較平穩數據改變量在左右凌晨一點半到早晨點半左右數據庫訪問極少
這是一個以寫為主的數據庫我們需要更多注意的是寫競爭
.Buffer命中率
Sql代碼
select
substr(to_char(snap_timeyyyymmddHH:MI))
round(*(((avalueevalue)+(bvaluefvalue))(cvaluegvalue))/
((avalueevalue)+(bvaluefvalue)))
BUFFERHITRATIO
from
perfstatstats$sysstata
perfstatstats$sysstatb
perfstatstats$sysstatc
perfstatstats$sysstatd
perfstatstats$sysstate
perfstatstats$sysstatf
perfstatstats$sysstatg
perfstatstats$snapshotsn
where
asnap_id=snsnap_id
and
bsnap_id=snsnap_id
and
csnap_id=snsnap_id
and
dsnap_id=snsnap_id
and
esnap_id=snsnap_id
and
fsnap_id=snsnap_id
and
gsnap_id=snsnap_id
and
astatistic#=
and
estatistic#=
and
bstatistic#=
and
fstatistic#=
and
cstatistic#=
and
gstatistic#=
and
dstatistic#=
select
substr(to_char(snap_timeyyyymmddHH:MI))
round(*(((avalueevalue)+(bvaluefvalue))(cvaluegvalue))/
((avalueevalue)+(bvaluefvalue)))
BUFFERHITRATIO
from
perfstatstats$sysstata
perfstatstats$sysstatb
perfstatstats$sysstatc
perfstatstats$sysstatd
perfstatstats$sysstate
perfstatstats$sysstatf
perfstatstats$sysstatg
perfstatstats$snapshotsn
where
asnap_id=snsnap_id
and
bsnap_id=snsnap_id
and
csnap_id=snsnap_id
and
dsnap_id=snsnap_id
and
esnap_id=snsnap_id
and
fsnap_id=snsnap_id
and
gsnap_id=snsnap_id
and
astatistic#=
and
estatistic#=
and
bstatistic#=
and
fstatistic#=
and
cstatistic#=
and
gstatistic#=
and
dstatistic#=
圖表
image javascript:return big(this) height= alt= src=http://imgeducitycn/img_///jpg width= javascript:if(thiswidth>)thisstylewidth=; border= twffan=done>
分析
Buffer(bufferhitratio)命中率是考察Oracle數據庫性能的重要指標它代表在內存中找到需要數據的比
率一般來說如果該值小於%則可能說明數據庫存在大量代價昂貴的IO操作數據庫需要調整
我們數據庫的buffer命中率幾乎接近%最低值在%左右這個比率是比較優化的
安裝statspack
borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=# border=>
ee>
SQL>connect/assysdba
SQL>@?/rdbms/admin/spcreate
卸載
borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=# border=>
ee>
SQL>connect/assysdba
SQL>@?/rdbms/admin/spdrop
/*
收集信息前把timed_statistics=true;
altersystemsettimed_statistics=true;
*/
收集信息
borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=# border=>
ee>
SQL>connectperfstat/perfstat
SQL>executestatspacksnap;
自動收集
borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=# border=>
ee>
SQL>connectperfstat/perfstat
SQL>@?/rdbms/admin/spauto
刪掉自動收集的job
borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=# border=>
ee>
SQL>select*fromuser_jobs;
SQL>execdbms_jobremove(JOB_ID)
/*
executestatspacksnap(i_snap_level=>i_modify_parameter=>true);
Levels=Additionaldata:SQLStatements
Levels=Thislevelincludesallstatisticsgatheredinthelowerlevel(s)
Levels=segmentslevelstatistics
Levels=Additionalstatistics:Childlatches
i_modify_parameter=>true/false決定是否保存level的值下一次執行繼續使用
*/
產生報告
borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=# border=>
ee>
SQL>conectperfstat/perfstat
SQL>@?/rdbms/admin/spreport
From:http://tw.wingwit.com/Article/program/Oracle/201311/18397.html