在本文中,我将介绍一些在Oracle中为不同目的生成AWR报告的方法。DBA应该知道可以生成两种类型的AWR报告。一种是单实例报告,另一种是群集数据库报告。
什么是自动工作量存储库(AWR)?AWR是一个用于存储Oracle数据库与性能相关的静态信息的地方。自动数据库诊断监视器(ADDM)是一种诊断工具,可以分析AWR数据,然后为数据库系统的任何发现提供建议。这套功能称为“自动性能诊断”。
为单实例数据库生成AWR报告
对于单实例数据库报告,您必须运行awrrpt.sql来生成AWR报告。
SQL> @?/rdbms/admin/awrrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
933515296 COMPDB 1 primdb
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: html
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 933515296 1 COMPDB primdb primary01.ex
ample.com
Using 933515296 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 <return> without
specifying a number lists all completed snapshots.
Enter value for num_days:
Listing all Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
primdb COMPDB 5 04 Feb 2016 09:10 1
6 04 Feb 2016 10:00 1
7 04 Feb 2016 11:00 1
8 04 Feb 2016 12:00 1
9 04 Feb 2016 13:00 1
10 04 Feb 2016 14:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 7
Begin Snapshot Id specified: 7
Enter value for end_snap: 8
End Snapshot Id specified: 8
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_7_8.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name:
Using the report name awrrpt_1_7_8.html
<html lang="en"><head><title>AWR Report for DB: COMPDB, Inst: primdb, Snaps: 7-8</title>
...
Report written to awrrpt_1_7_8.html
SQL> !
[oracle@primary01 ~]$ ll
...
-rw-r--r--. 1 oracle oinstall 533219 Feb 4 14:12 awrrpt_1_7_8.html
[oracle@primary01 ~]$ exit
...
其中,@(符号)表示它从以下字符串开始执行。?(问号)表示$ORACLE_HOME。有关更多说明,您可以参考这篇文章:Oracle数据库中使用了哪些符号?
生成群集数据库的AWR报告
生成AWR报告有两种基本类型,一种是特定于实例级别的,另一种特定于数据库级别的。
实例级
对于实例级报告,您必须运行awrrpti.sql一次生成一个AWR报告。在这种情况下,我们选择实例2作为报告的主要来源。
SQL> @?/rdbms/admin/awrrpti.sql
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type:
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 3240481230 1 ERPFINDB erpfindb1 rac1
3240481230 2 ERPFINDB erpfindb2 rac2
Enter value for dbid: 3240481230
Using 3240481230 for database Id
Enter value for inst_num: 2
Using 2 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 <return> without
specifying a number lists all completed snapshots.
Enter value for num_days: 8
Listing the last 8 days of Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
erpfindb1 ERPFINDB 83611 16 Apr 2019 00:00 1
...
...
83679 23 Apr 2019 00:00 1
...
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 83611
Begin Snapshot Id specified: 83611
Enter value for end_snap: 83679
End Snapshot Id specified: 83679
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_2_83611_83679.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: awr_instance_2_report_20190423.html
...
全局级别
对于全局级别的报告,必须运行awrgrpt.sql才能为群集数据库全局生成AWR报告。
SQL> @?/rdbms/admin/awrgrpt.sql
Current Database
~~~~~~~~~~~~~~~~
DB Id DB Name
----------- ------------
3240481230 ERPFINDB
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type:
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id INSTT_NUM DB Name
------------ ---------- ------------
INSTT_NAME Host
------------------------------------------------ ------------
* 3240481230 1 ERPFINDB
erpfindb1 rac1
* 3240481230 2 ERPFINDB
erpfindb2 rac2
Using 3240481230 for database Id
Using instances ALL (default 'ALL')
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.
Enter value for num_days: 8
Listing the last 8 days of Completed Snapshots
Snap
DB Name Snap Id Snap Started Level
------------ --------- ------------------ -----
ERPFINDB 83611 16 Apr 2019 00:00 1
...
...
83679 23 Apr 2019 00:00 1
...
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 83611
Begin Snapshot Id specified: 83611
Enter value for end_snap: 83679
End Snapshot Id specified: 83679
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_rac_83611_83679.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: awr_global_database_report_20190423.html
...
报告范围的差异
让我们总结一下SQL脚本之间统计范围的差异,如下图所示。
序号 |
脚本 |
范围 |
1 |
awrrpt.sql |
当前实例 |
2 |
awrrpti.sql |
选定的实例 |
3 |
awrgrpt.sql |
整个集群数据库, |
尽管我们使用awrgrpt.sql为整个群集数据库生成AWR报告,但是我们可以拥有由awrrpti.sql生成的更详细的实例AWR报告。