Oracle 生成AWR报告评估性能的方法

AWRAutomatic Workload Repository)报告是咱们进行平常数据库性能评定、问题SQL发现的重要手段。熟练掌握AWR报告,是作好开发、运维DBA工做的重要基本功。 html

AWR报告的原理是基于Oracle数据库的定时镜像功能。默认状况下,Oracle数据库后台进程会以必定间隔(一小时)收集系统当前状态镜像,而且保存在数据库中。生成AWR报告时,只须要指定进行分析的时间段(开始镜像编号和结束镜像编号),就能够生成该时间段的性能分析状况。AWR镜像保存在数据库中的时间为一个月左右。 sql

目前Oracle10g以后,AWR报告取代了原先的Statspack报告成为一个主流性能分析报告。一般能够从OEMOracle Enterprise Manager Console)平台上生成查看AWR报告。在OEM中,使用图形化方法更加容易。本篇中介绍使用手工脚本方式生成AWR的方法,脱离OEM的限制。 数据库

一、一、运行脚本 浏览器

首先,切换到Oracle用户身份,报告会生成在当前路径 oracle

# su - oracle

 

启动sqlplus等开发工具,调用生成脚本。程序脚本通常保存在$ORACLE_HOME下的rdbms/admin中,名称为awrrpt.sql 运维

$ sqlplus / as sysdba ssh

SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 27 10:45:08 2015 工具

SQL> @?/rdbms/admin/awrrpt.sql
性能

 

2、输入报告参数 开发工具

以后,要持续输入一系列的报告参数。

输入生成报告类型,目前AWR提供txthtml两种格式。须要确认生成格式,默认是html格式。

Current Instance
~~~~~~~~~~~~~~~~

   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 1986520570 ZLRTDB              1 zlrtdb


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
------------ -------- ------------ ------------ ------------
* 1986520570        1 ZLRTDB       zlrtdb       sjk1

Using 1986520570 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: 7


ü    报告涉及天数范围

启动报告后,会显示生成实例的名称等基本信息。

默认状况下,AWR会将镜像信息保留一个月。手工生成的时候,须要确认生成AWR报告的时间范围。通常状况下,特别是生产环境下,咱们一般设置1-7天也就够用了。

输入天数信息后,AWR生成代码会将天数范围内的snapshot镜像点列出,供输入选择,以下所示:


Listing the last 7 days of Completed Snapshots

                                                        Snap
Instance     DB Name        Snap Id    Snap Started    Level
------------ ------------ --------- ------------------ -----
zlrtdb       ZLRTDB           14583 21 Nov 2015 00:00      1
                              14584 21 Nov 2015 01:00      1
                              14585 21 Nov 2015 02:00      1
                              14586 21 Nov 2015 03:00      1

下面省略了不少快照列表 ……

                       14735 27 Nov 2015 08:00      1
                       14736 27 Nov 2015 09:00      1
                       14737 27 Nov 2015 10:00      1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 14583
Begin Snapshot Id specified: 14583

Enter value for end_snap: 14737

ü    输入开始和结束的snapshot编号,这里开始输入14583,结束输入14737


Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_14583_14737.html.  To use this name,
press <return> to continue, otherwise enter an alternative.

Enter value for report_name:  2015-11-21-27.awr.html         #默认报告名是awrrpt_1_14583_14737.html

 

以后输出报告的内容到屏幕上,此处不加以累述。最后提示报告成功写入了文件2015-11-21-27.awr.html。

Report written to 2015-11-21-27.awr.html
SQL> quit

退出SQL工具,能够在当前目录下能够发现报告文件。

三、能够把该报告文件经过ssh工具下载到本地,用浏览器打开就能够分析了。

 
相关文章
相关标签/搜索