AWR(Automatic Workload Repository)報告是我們進行日常數據庫性能評定、問題SQL發現的重要手段。熟練掌握AWR報告,是做好開發、運維DBA工作的重要基本功。
AWR報告的原理是基于Oracle數據庫的定時鏡像功能。默認情況下,Oracle數據庫后臺進程會以一定間隔(一小時)收集系統當前狀態鏡像,并且保存在數據庫中。生成AWR報告時,只需要指定進行分析的時間段(開始鏡像編號和結束鏡像編號),就可以生成該時間段的性能分析情況。AWR鏡像保存在數據庫中的時間為一個月左右。
目前Oracle10g之后,AWR報告取代了原先的Statspack報告成為一個主流性能分析報告。通常可以從OEM(Oracle Enterprise ManagerConsole)平臺上生成查看AWR報告。在OEM中,使用圖形化方法更加容易。本篇中介紹使用手工腳本方式生成AWR的方法,脫離OEM的限制。
1、?運行腳本
首先,準備一個目錄作為AWR生成報告的路徑。
[oracle@bspdev /]$ ls -l | greptest
drwxr-xr-x.??2oracle oinstall?4096 Jun 21 13:01test
[oracle@bspdev /]$ cdtest
啟動sqlplus等開發工具,調用生成腳本。程序腳本一般保存在$ORACLE_HOME下的rdbms/admin中,名稱為awrrpt.sql。
[oracle@bspdev test]$ sqlplus/nolog
SQL*Plus: Release11.2.0.1.0 Production onTue Jun 21 13:04:44 2011
Copyright (c) 1982, 2009,Oracle.?Allrights reserved.
SQL> conn / as sysdba
Connected.
--調用腳本,生成文件
SQL>@?/rdbms/admin/awrrpt.sql
之后進入報告參數輸入模塊。
2、輸入報告參數
之后,要持續輸入一系列的報告參數。
ü輸入生成報告類型,目前AWR提供txt和html兩種格式。需要確認生成格式,默認是html格式。
Current Instance
~~~~~~~~~~~~~~~~
DBId???DBName?????InstNum Instance
----------- ------------ --------------------
4143510747 ORA11G?????????????1ora11g
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plaintext report?
Enter 'html' for an HTMLreport, or 'text' for plain text
Defaults to'html'
ü報告涉及天數范圍
啟動報告后,會顯示生成實例的名稱等基本信息。
默認情況下,AWR會將鏡像信息保留一個月。手工生成的時候,需要確認生成AWR報告的時間范圍。一般情況下,特別是生產環境下,我們通常設置1-7天也就夠用了。
Instances in this Workload Repositoryschema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DBId????InstNum DB Name?????Instance????Host
------------ -------- ------------------------ ------------
* 4143510747???????1ORA11G??????ora11g??????bspdev.local
domain
Using 4143510747 for databaseId
Using?????????1for instance number
Specify the number of days of snapshots tochoose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will resultin the most recent
(n) days of snapshots beinglisted.?Pressingwithout
specifying a number lists all completedsnapshots.
Enter value for num_days:3
ü輸入開始和結束的snapshot編號
輸入天數信息后,AWR生成代碼會將天數范圍內的snapshot鏡像點列出,供輸入選擇。
Listing the last 3 days of CompletedSnapshots
Snap
Instance????DBName???????SnapId???SnapStarted???Level
------------ ------------ --------------------------- -----
ora11g??????ORA11G???????????178920 Jun 2011 13:01?????1
179020 Jun 2011 14:00?????1
179120 Jun 2011 15:00?????1
179220 Jun 2011 16:00?????1
(篇幅原因,有省略……)
181121 Jun 2011 11:00?????1
181221 Jun 2011 12:00?????1
181321 Jun 2011 13:00?????1
Specify the Begin and End SnapshotIds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
之后,我們需要根據列出的時間范圍,輸入開始和結束的snap編號。
Specify the Begin and End SnapshotIds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap:1796
Begin Snapshot Id specified:1796
Enter value for end_snap:1813
ü確定報告名稱
最后就是確定生成報告的名稱。一般采用默認的名稱就可以了。
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name isawrrpt_1_1796_1813.html.?To use thisname,
press to continue, otherwise enter analternative.
Enter value forreport_name:
之后輸出內容很多,此處不加以累述。最后提示報告生成成功。
Report written toawrrpt_1_1796_1813.html
于是,指定目錄上可以看到相應的報告文件。
[oracle@bspdev test]$ ls-l
total 508
-rw-r--r--. 1 oracle oinstall 515262 Jun 2113:10 awrrpt_1_1796_1813.html
3、說明兩個問題
首先,此處生成的html格式的報表。如果要求生成txt格式,就在生成過程中選擇text格式報表。
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plaintext 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 toawrrpt_1_1789_1800.txt
[oracle@bspdev test]$ ls-l
total 692
-rw-r--r--. 1 oracle oinstall 180601 Jun 2113:27 awrrpt_1_1789_1800.txt
-rw-r--r--. 1 oracle oinstall 515262 Jun 2113:10 awrrpt_1_1796_1813.html
第二個就是調用腳本的方式問題。調用時使用的sqlplus客戶端可以在Oracle服務器本機上(遠程登錄),也可以在客戶端機器本機上。筆者建議是在客戶端本機上進行生成,這樣可以避免報告文件來回拷貝的工作。但是最好要保證客戶端版本與服務器版本相匹配。
4、結論
手工生成AWR報告,可以避免受到OEM的限制約束,而且靈活度高。本篇記錄,權當備忘。