AWR(Automatic Workload Repository)报告是我们进行日常数据库性能评定、问题SQL发现的重要手段。熟练掌握AWR报告,是做好开发、运维DBA工作的重要基本功。
AWR报告的原理是基于Oracle数据库的定时镜像功能。默认情况下,Oracle数据库后台进程会以一定间隔(一小时)收集系统当前状态镜像,并且保存在数据库中。生成AWR报告时,只需要指定进行分析的时间段(开始镜像编号和结束镜像编号),就可以生成该时间段的性能分析情况。AWR镜像保存在数据库中的时间为一个月左右。
目前Oracle10g之后,AWR报告取代了原先的Statspack报告成为一个主流性能分析报告。通常可以从OEM(Oracle Enterprise Manager Console)平台上生成查看AWR报告。在OEM中,使用图形化方法更加容易。本篇中介绍使用手工脚本方式生成AWR的方法,脱离OEM的限制。
1、 运行脚本
首先,准备一个目录作为AWR生成报告的路径。
[oracle@bspdev /]$ ls -l | grep test
drwxr-xr-x. 2 oracle oinstall 4096 Jun 21 13:01 test
[oracle@bspdev /]$ cd test
启动sqlplus等开发工具,调用生成脚本。程序脚本一般保存在$ORACLE_HOME下的rdbms/admin中,名称为awrrpt.sql。
[oracle@bspdev test]$ sqlplus /nolog
SQL*Plus: Release 11.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> @?/rdbms/admin/awrrpt.sql
之后进入报告参数输入模块。
2、输入报告参数
之后,要持续输入一系列的报告参数。
? 输入生成报告类型,目前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'
? 报告涉及天数范围
启动报告后,会显示生成实例的名称等基本信息。
默认情况下,AWR会将镜像信息保留一个月。手工生成的时候,需要确认生成AWR报告的时间范围。一般情况下,特别是生产环境下,我们通常设置1-7天也就够用了。
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 4143510747 1 ORA11G ora11g bspdev.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
? 输入开始和结束的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
? 确定报告名称
最后就是确定生成报告的名称。一般采用默认的名称就可以了。
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@bspdev test]$ 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@bspdev 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
第二个就是调用脚本的方式问题。调用时使用的sqlplus客户端可以在Oracle服务器本机上(远程登录),也可以在客户端机器本机上。笔者建议是在客户端本机上进行生成,这样可以避免报告文件来回拷贝的工作。但是最好要保证客户端版本与服务器版本相匹配。
4、结论
手工生成AWR报告,可以避免受到OEM的限制约束,而且灵活度高。本篇记录,权当备忘。
第二篇:AWR生成方法汇总
AWR分析报告提取操作方法
oracle遇到性能问题时,性能分析的一个思路就是导出AWR分析报告,通过报告分析定位问题根源,以下是如何生成分析报告的步骤,AWR分析报告文件类型分为txt和html两种,习惯使用html。
准备工作:现在我们使用的都是11GR2的数据库,安装完成后什么都不需要任何修改。 操作说明:其中红色的部分为需要输入的内容。
Windows平台
C:\>sqlplus/nolg
C:\>sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期三 9月 12 13:56:09 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> conn sys/zlsoft@demo as sysdba
已连接。
SQL> @?/rdbms/admin/awrrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
1270982830 DEMO 1 demo
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 的值: html
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
1270982830 1 ORCL orcl USER01
* 1270982830 1 DEMO demo QW_TEST_SEVE
R
Using 1270982830 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.
输入 num_days 的值: 2
Listing the last 2 days of Completed Snapshots
Snap Instance DB Name Snap Id Snap Started Level ------------ ------------ --------- ------------------ -----
demo DEMO 12859 11 9月 2012 00:00 1 12860 11 9月 2012 01:00 1 12861 11 9月 2012 02:00 1 12862 11 9月 2012 03:00 1 12863 11 9月 2012 04:00 1 12864 11 9月 2012 05:00 1 12865 11 9月 2012 06:00 1 12866 11 9月 2012 07:00 1 12867 11 9月 2012 08:00 1 12868 11 9月 2012 09:00 1 12869 11 9月 2012 10:00 1 12870 11 9月 2012 11:00 1 12871 11 9月 2012 12:00 1 12872 11 9月 2012 13:00 1 12873 11 9月 2012 14:00 1 12874 11 9月 2012 15:00 1 12875 11 9月 2012 16:00 1 12876 11 9月 2012 17:00 1 12877 11 9月 2012 18:00 1 12878 11 9月 2012 19:00 1 12879 11 9月 2012 20:00 1 12880 11 9月 2012 21:00 1 12881 11 9月 2012 22:00 1 12882 11 9月 2012 23:00 1 12883 12 9月 2012 00:00 1 12884 12 9月 2012 01:00 1 12885 12 9月 2012 02:00 1 12886 12 9月 2012 03:00 1
12887 12 9月 2012 04:00 1
12888 12 9月 2012 05:00 1
12889 12 9月 2012 06:00 1
12890 12 9月 2012 07:00 1
12891 12 9月 2012 08:00 1
12892 12 9月 2012 09:00 1
12893 12 9月 2012 10:00 1
12894 12 9月 2012 11:00 1
12895 12 9月 2012 12:00 1
12896 12 9月 2012 13:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入 begin_snap 的值: 12884
Begin Snapshot Id specified: 12884
输入 end_snap 的值: 12895
End Snapshot Id specified: 12895
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_12884_12895.html. To use this name, press<return> to continue, otherwise enter an alternative.
输入 report_name 的值: test.html
Using the report name test.html
另外一种方法
1:登陆对应的数据库服务器
2:找到oracle磁盘空间(d:oracle\product\10.2.0\db_1\RDBMS\Admin) 3:执行cmd-cd d:回车
4: cd d:oracle\product\10.2.0\db_1\RDBMS\Admin 回车
5:sqlplus 用户名/密码@服务连接名(例:sqlplus carmot_esz_1/carmot@igrp) 6:执行@awrrpt.sql 回车
解释:
第一步输入类型: html
第二步输入天数:天数自定义(如1,代表当天,如果2,代表今天和昨天。。。) 第三步输入开始值与结束值:(你可以看到上面列出的数据,snap值) 这个值输入开始,与结束
第四步输入导出表的名称:名称自定义回车
第五步,由程序自动导完。
linux下的操作
[root@linux5 /]# su – oracle:注意用户的选择
[oracle@linux5 ~]$ export ORACLE_SID=orcl:环境变量[oracle@linux5 ~]$export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"字符集,可选
[oracle@linux5 admin]$ sqlplus /nolog
SQL>conn sys/XXX@ORCL as sysdba
已连接.
SQL>@?/rdbms/admin/awrrpt.sql Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
1260101618 ORCL 1 orcl
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
------------ -------- ------------ ------------ ------------
* 1260101618 1 ORCL orcl linux5
Using 1260101618 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: 3 “报告输出的时间范围选择”
Listing the last 3 days of Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
orcl ORCL 1 13 Oct 2010 23:00 1
2 14 Oct 2010 00:00 1
3 14 Oct 2010 01:00 1
4 14 Oct 2010 02:00 1
5 14 Oct 2010 03:00 1
6 14 Oct 2010 04:00 1 7 14 Oct 2010 05:00 1
8 14 Oct 2010 06:00 1
9 14 Oct 2010 07:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
“选择获取报告的快照范围”
Enter value for begin_snap: 2
Begin Snapshot Id specified: 2
Enter value for end_snap: 9
End Snapshot Id specified: 9
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_2_9.html. To use this name,
press <return> to continue, otherwise enter an alternative.
“输出分析报告文件”
Enter value for report_name: /opt/awrrpt.html
简单方法(远程登录)
在使用linux的环境下,当我们对linux不是很熟悉的情况下就可以用调用脚本的方式解决问题。使用在安装sqlplus客户端的WINDOWS机器上远程登录Oracle服务器,运行在在客户端机器本机上。建议是在客户端本机上进行生成,这样报告文件可以在客户端机器上生成AWR报告。但是最好要保证客户端版本与服务器版本相匹配。
操作方法就是和Windows下的操作一样(略)。