Oracle AWR(Automatic Workload Repository) 說明


http://blog.csdn.net/tianlesoftware/article/details/4682300

. AWR 說明

Oracle 10g之前對數據庫做性能檢測使用statspack工具。關於statspack的說明,參考我的Blog

statspack安裝使用 report 分析

http://blog.csdn.net/tianlesoftware/archive/2009/10/16/4682329.aspx

Oracle Database 10g 提供了一個新的工具:(AWR:Automatic Workload Repository)Oracle 建議用戶用這個取代 StatspackAWR 實質上是一個 Oracle 的內置工具,它採集與性能相關的統計數據,並從那些統計數據中導出性能量度,以跟蹤潛在的問題。

Statspack 不同,快照由一個稱爲 MMON 的新的後臺進程及其從進程自動地每小時採集一次。爲了節省空間,採集的數據在 7 天后自動清除。快照頻率和保留時間都可以由用戶修改。它產生兩種類型的輸出:文本格式(類似於 Statspack 報表的文本格式但來自於 AWR 信息庫)和默認的 HTML 格式(擁有到部分和子部分的所有超鏈接),從而提供了非常用戶友好的報表。

AWR 使用幾個表來存儲採集的統計數據,所有的表都存儲在新的名稱爲 SYSAUX 的特定表空間中的 SYS 模式下,並且以 WRM$_* WRH$_* 的格式命名。前一種類型存儲元數據信息(如檢查的數據庫和採集的快照),後一種類型保存實際採集的統計數據。H 代表“歷史數據 (historical)”而 M 代表“元數據 (metadata)”。

在這些表上構建了幾種帶前綴 DBA_HIST_ 的視圖,這些視圖可以用來編寫您自己的性能診斷工具。視圖的名稱直接與表相關;例如,視圖 DBA_HIST_SYSMETRIC_SUMMARY 是在WRH$_SYSMETRIC_SUMMARY 表上構建的。

注意一點:

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 72009 08:111

143 03 72009 09:001

144 03 72009 10:001

145 03 72009 11:001

146 03 72009 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:SQLElapsed 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),就不能不說一下Oraclesql的處理過程。

4.7 SQL ordered by Sharable Memory:

記錄了SQL佔用library cache的大小的TOP SQLSharable 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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章