手工生成AWR分析報告

abraham_dba_2013發表於2014-01-16
      AWR(Automatic Workload Repository)報告是我們進行日常資料庫效能評定、問題SQL發現的重要手段。熟練掌握AWR報告,是做好開發、運維DBA工作的重要基本功。
      AWR 實質上是一個 Oracle 的內建工具,它採集與效能相關的統計資料,並從那些統計資料中匯出效能量度,以跟蹤潛在的問題。快照由一個稱為 MMON 的後臺程式及其從程式自動地每小時採集一次。為了節省空間,採集的資料在 7 天后自動清除。快照頻率和保留時間都可以由使用者修改。它產生兩種型別的輸出:文字格式和預設的 HTML 格式,從而提供了非常使用者友好的報表。
       AWR 使用幾個表來儲存採集的統計資料,所有的表都儲存在SYSAUX 的特定表空間中的 SYS 模式下,並且以 WRM$_* 和 WRH$_* 的格式命名。前一種型別儲存後設資料資訊(如檢查的資料庫和採集的快照),後一種型別儲存實際採集的統計資料。H 代表“歷史資料 (historical)”而 M 代表“後設資料 (metadata)”。在這些表上構建了幾種帶字首 DBA_HIST_ 的檢視,這些檢視可以用來編寫您自己的效能診斷工具。檢視的名稱直接與表相關;例如,檢視 DBA_HIST_SYSMETRIC_SUMMARY 是在WRH$_SYSMETRIC_SUMMARY 表上構建的。
       本篇中介紹使用手工指令碼方式生成AWR的方法,脫離OEM的限制。 
1、 執行指令碼 
首先,準備一個目錄作為AWR生成報告的路徑。 
[oracle@abraham_dba/]$ mkdir -p rpt
drwxr-xr-x.  2 oracle oinstall 4096 Jun 21 13:01 test 
[oracle@abraham_dba /]$ cd rpt 
啟動sqlplus等開發工具,呼叫生成指令碼。程式指令碼一般儲存在$ORACLE_HOME下的rdbms/admin中,名稱為awrrpt.sql。 
[oracle@abraham_dba rpt]$ sqlplus /nolog
SQL*Plus: Release11.2.0.1.0 Production on Tue Jun 21 13:04:44 2011 
Copyright (c) 1982, 2009, Oracle. All rights reserved. 
SQL> conn / as sysdba
Connected. 
--呼叫指令碼,生成檔案
SQL> @$ORACLE_HOME/rdbms/admin/awrrpt.sql 
之後進入報告引數輸入模組。 
2、輸入報告引數 
之後,要持續輸入一系列的報告引數。 
2.1.輸入生成報告型別,目前AWR提供txt和html兩種格式。需要確認生成格式,預設是html格式。 
Current Instance
~~~~~~~~~~~~~~~~ 
  DB Id   DB Name     Inst Num Instance
----------- ------------ -------- ------------
 4143510747 ORA11G             1 ora11g  
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' 
2.2.報告涉及天數範圍 
啟動報告後,會顯示生成例項的名稱等基本資訊。 
預設情況下,AWR會將映象資訊保留一個月。手工生成的時候,需要確認生成AWR報告的時間範圍。一般情況下,特別是生產環境下,我們通常設定1-7天也就夠用了。 
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  DB Id    Inst Num DB Name     Instance    Host
------------ -------- ------------ ------------ ------------
* 4143510747       1 ORA11G      ora11g      abraham_dba.local
                                               domain 
Using 4143510747 for database Id
Using         1 for instance number 
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 without
specifying a number lists all completed snapshots. 
Enter value for num_days:3  
2.3.輸入開始和結束的snapshot編號 
輸入天數資訊後,AWR生成程式碼會將天數範圍內的snapshot映象點列出,供輸入選擇。 
Listing the last 3 days of Completed Snapshots 
                                                       Snap
Instance    DB Name       Snap Id   Snap Started   Level
------------ ------------ --------- ------------------ -----
ora11g      ORA11G           1789 20 Jun 2011 13:01     1
                              1790 20 Jun 2011 14:00     1
                              1791 20 Jun 2011 15:00     1
                              1792 20 Jun 2011 16:00     1
                              1811 21 Jun 2011 11:00     1
                              1812 21 Jun 2011 12:00     1
                              1813 21 Jun 2011 13:00     1 
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
之後,我們需要根據列出的時間範圍,輸入開始和結束的snap編號。 
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap:1796
Begin Snapshot Id specified: 1796 
Enter value for end_snap:1813  
2.4.確定報告名稱 
最後就是確定生成報告的名稱。一般採用預設的名稱就可以了。 
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_1796_1813.html. To use this name,
press to continue, otherwise enter an alternative. 
Enter value for report_name: 
之後輸出內容很多,此處不加以累述。最後提示報告生成成功。 
Report written to awrrpt_1_1796_1813.html 
於是,指定目錄上可以看到相應的報告檔案。 
[oracle@abraham_dba rpt]$ ls -l
total 508
-rw-r--r--. 1 oracle oinstall 515262 Jun 21 13:10 awrrpt_1_1796_1813.html   
3、說明兩個問題 
首先,此處生成的html格式的報表。如果要求生成txt格式,就在生成過程中選擇text格式報表。 
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'
Enter value for report_type: text 
Type Specified: text 
End of Report
Report written to awrrpt_1_1789_1800.txt 
[oracle@abraham_dba test]$ ls -l
total 692
-rw-r--r--. 1 oracle oinstall 180601 Jun 21 13:27 awrrpt_1_1789_1800.txt
-rw-r--r--. 1 oracle oinstall 515262 Jun 21 13:10 awrrpt_1_1796_1813.html 
4、結論 
手工生成AWR報告,可以避免受到OEM的限制約束,而且靈活度高。本篇記錄,權當備忘
參考:
1、http://space.itpub.net/17203031/viewspace-700471 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29439655/viewspace-1071674/,如需轉載,請註明出處,否則將追究法律責任。

相關文章