http://blog.csdn.net/tianlesoftware/article/details/4682300
html
一. AWR 說明sql
Oracle 10g以前對數據庫作性能檢測使用statspack工具。關於statspack的說明,參考個人Blog:chrome
statspack安裝使用和 report 分析數據庫
http://blog.csdn.net/tianlesoftware/archive/2009/10/16/4682329.aspxsession
Oracle Database 10g 提供了一個新的工具:(AWR:Automatic Workload Repository)。Oracle 建議用戶用這個取代 Statspack。AWR 實質上是一個 Oracle 的內置工具,它採集與性能相關的統計數據,並從那些統計數據中導出性能量度,以跟蹤潛在的問題。app
與 Statspack 不一樣,快照由一個稱爲 MMON 的新的後臺進程及其從進程自動地每小時採集一次。爲了節省空間,採集的數據在 7 天后自動清除。快照頻率和保留時間均可以由用戶修改。它產生兩種類型的輸出:文本格式(相似於 Statspack 報表的文本格式但來自於 AWR 信息庫)和默認的 HTML 格式(擁有到部分和子部分的全部超連接),從而提供了很是用戶友好的報表。ide
AWR 使用幾個表來存儲採集的統計數據,全部的表都存儲在新的名稱爲 SYSAUX 的特定表空間中的 SYS 模式下,而且以 WRM$_* 和 WRH$_* 的格式命名。前一種類型存儲元數據信息(如檢查的數據庫和採集的快照),後一種類型保存實際採集的統計數據。H 表明「歷史數據 (historical)」而 M 表明「元數據 (metadata)」。工具
在這些表上構建了幾種帶前綴 DBA_HIST_ 的視圖,這些視圖能夠用來編寫您本身的性能診斷工具。視圖的名稱直接與表相關;例如,視圖 DBA_HIST_SYSMETRIC_SUMMARY 是在WRH$_SYSMETRIC_SUMMARY 表上構建的。性能
注意一點:ui
statistics_level 默認是typical,在10g中表監控是激活的,強烈建議在10g中此參數的值是typical。如果STATISTICS_LEVEL設置爲basic,不只不能監控表,並且將禁掉以下一些10g的新功能:
ASH(Active Session History)
ASSM(Automatic Shared Memory Management)
AWR(Automatic Workload Repository)
ADDM(Automatic Database Diagnostic Monitor)
在Oracle 11gR2裏禁用的功能以下:
STATISTICS_LEVEL
specifies the level of collection for database and operating system statistics. The Oracle Database collects these statistics for a variety of purposes, including making self-management decisions.
The default setting of TYPICAL
ensures collection of all major statistics required for database self-management functionality and provides best overall performance. The default value should be adequate for most environments.
When the STATISTICS_LEVEL
parameter is set to ALL
, additional statistics are added to the set of statistics collected with the TYPICAL
setting. The additional statistics are timed OS statistics and plan execution statistics.
Setting the STATISTICS_LEVEL
parameter to BASIC
disables the collection of many of the important statistics required by Oracle Database features and functionality, including:
Automatic Workload Repository (AWR) Snapshots
Automatic Database Diagnostic Monitor (ADDM)
All server-generated alerts
Automatic SGA Memory Management
Automatic optimizer statistics collection
Object level statistics
End to End Application Tracing (V$CLIENT_STATS
)
Database time distribution statistics (V$SESS_TIME_MODEL
and V$SYS_TIME_MODEL
)
Service level statistics
Buffer cache advisory
MTTR advisory
Shared pool sizing advisory
Segment level statistics
PGA Target advisory
Timed statistics
Monitoring of statistics
二.AWR使用
SQL>@?/rdbms/admin/awrrpt.sql
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
輸入 report_type 的值:
Type Specified:html
Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.Pressing <return> without
specifying a number lists all completed snapshots.
輸入 num_days 的值:1
Listing the last day's Completed Snapshots
Snap
InstanceDB NameSnap IdSnap StartedLevel
------------ ------------ --------- ------------------ -----
orcl10gORCL10G142 03 7月2009 08:111
143 03 7月2009 09:001
144 03 7月2009 10:001
145 03 7月2009 11:001
146 03 7月2009 12:011
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
輸入 begin_snap 的值:142
Begin Snapshot Id specified: 142
輸入 end_snap 的值:146
EndSnapshot Id specified: 146
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_142_146.html.To use this name,
press <return> to continue, otherwise enter an alternative.
輸入 report_name 的值:D:/awrrpt_1_142_146.html
Report written to D:/awrrpt_1_142_146.html
三. AWR 操做
3.1. 查看當前的AWR保存策略
SQL> col SNAP_INTERVAL format a20
SQL> col RETENTION format a20
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVALRETENTIONTOPNSQL
---------- -------------------- -------------------- ----------
262089084 +00000 01:00:00.0+00007 00:00:00.0DEFAULT
以上結果表示,每小時產生一個SNAPSHOT,保留7天。
3.2. 調整AWR配置
AWR配置都是經過dbms_workload_repository包進行配置。
3.2.1 調整AWR產生snapshot的頻率和保留策略,如將收集間隔時間改成30 分鐘一次。而且保留5天時間(單位都是分鐘):
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30, retention=>5*24*60);
3.2.2 關閉AWR,把interval設爲0則關閉自動捕捉快照
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>0);
3.2.3 手工建立一個快照
SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT();
3.2.4 查看快照
SQL> select * from sys.wrh$_active_session_history
3.2.5 手工刪除指定範圍的快照
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(low_snap_id => 973, high_snap_id => 999, dbid => 262089084);
3.2.6 建立baseline,保存這些數據用於未來分析和比較
SQL> exec dbms_workload_repository.create_baseline(start_snap_id => 1003, end_snap_id => 1013, 'apply_interest_1');
3.2.7 刪除baseline
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(baseline_name => 'apply_interest_1', cascade => FALSE);
3.2.8 將AWR數據導出並遷移到其它數據庫以便於之後分析
SQL> exec DBMS_SWRF_INTERNAL.AWR_EXTRACT(dmpfile => 'awr_data.dmp', mpdir => 'DIR_BDUMP', bid => 1003, eid => 1013);
3.2.9 遷移AWR數據文件到其餘數據庫
SQL> exec DBMS_SWRF_INTERNAL.AWR_LOAD(SCHNAME => 'AWR_TEST', dmpfile => 'awr_data.dmp', dmpdir => 'DIR_BDUMP');
把AWR數據轉移到SYS模式中:
SQL> exec DBMS_SWRF_INTERNAL.MOVE_TO_AWR (SCHNAME => 'TEST');
四. AWR 報告分析
這部份內容,能夠參考statspack,這2個內容都差很少。
statspack安裝使用和 report 分析
http://blog.csdn.net/tianlesoftware/archive/2009/10/16/4682329.aspx
4.1 SQL ordered by Elapsed Time
記錄了執行總和時間的TOP SQL(請注意是監控範圍內該SQL的執行時間總和,而不是單次SQL執行時間 Elapsed Time = CPU Time + Wait Time)。
Elapsed Time(S): SQL語句執行用總時長,此排序就是按照這個字段進行的。注意該時間不是單個SQL跑的時間,而是監控範圍內SQL執行次數的總和時間。單位時間爲秒。Elapsed Time = CPU Time + Wait Time
CPU Time(s): 爲SQL語句執行時CPU佔用時間總時長,此時間會小於等於Elapsed Time時間。單位時間爲秒。
Executions: SQL語句在監控範圍內的執行次數總計。
Elap per Exec(s):執行一次SQL的平均時間。單位時間爲秒。
% Total DB Time:爲SQL的Elapsed Time時間佔數據庫總時間的百分比。
SQL ID: SQL語句的ID編號,點擊以後就能導航到下邊的SQL詳細列表中,點擊IE的返回能夠回到當前SQL ID的地方。
SQL Module: 顯示該SQL是用什麼方式鏈接到數據庫執行的,若是是用SQL*Plus或者PL/SQL連接上來的那基本上都是有人在調試程序。通常用前臺應用連接過來執行的sql該位置爲空。
SQL Text: 簡單的sql提示,詳細的須要點擊SQL ID。
4.2 SQL ordered by CPU Time:
記錄了執行佔CPU時間總和時間最長的TOP SQL(請注意是監控範圍內該SQL的執行佔CPU時間總和,而不是單次SQL執行時間)。
4.3 SQL ordered by Gets:
記錄了執行佔總buffer gets(邏輯IO)的TOP SQL(請注意是監控範圍內該SQL的執行佔Gets總和,而不是單次SQL執行所佔的Gets)。
4.4 SQL ordered by Reads:
記錄了執行佔總磁盤物理讀(物理IO)的TOP SQL(請注意是監控範圍內該SQL的執行佔磁盤物理讀總和,而不是單次SQL執行所佔的磁盤物理讀)。
4.5 SQL ordered by Executions:
記錄了按照SQL的執行次數排序的TOP SQL。該排序能夠看出監控範圍內的SQL執行次數。
4.6 SQL ordered by Parse Calls:
記錄了SQL的軟解析次數的TOP SQL。說到軟解析(soft prase)和硬解析(hard prase),就不能不說一下Oracle對sql的處理過程。
4.7 SQL ordered by Sharable Memory:
記錄了SQL佔用library cache的大小的TOP SQL。Sharable Mem (b):佔用library cache的大小,單位是byte。
4.8 SQL ordered by Version Count:
記錄了SQL的打開子游標的TOP SQL。
4.9 SQL ordered by Cluster Wait Time:
記錄了集羣的等待時間的TOP SQL