加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle手工生成AWR报告方法记录

发布时间:2020-12-12 16:20:23 所属栏目:百科 来源:网络整理
导读:AWR (Automatic Workload Repository)报告是我们进行日常 数据库 性能评定、问题 SQL 发现的重要手段。熟练掌握AWR报告,是做好开发、运维DBA工作的重要基本功。 AWR报告的原理是基于 Oracle 数据库的定时镜像功能。默认情况下,Oracle数据库后台进程会以

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 oinstall4096 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

~~~~~~~~~~~~~~~~

DBIdDBNameInstNum Instance

----------- ------------ --------------------

4143510747 ORA11G1ora11g

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DBIdInstNum DB NameInstanceHost

------------ -------- ------------------------ ------------

* 41435107471ORA11Gora11gbspdev.local

domain

Using 4143510747 for databaseId

Using1for 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

InstanceDBNameSnapIdSnapStartedLevel

------------ ------------ --------------------------- -----

ora11gORA11G178920 Jun 2011 13:011

179020 Jun 2011 14:001

179120 Jun 2011 15:001

179220 Jun 2011 16:001

(篇幅原因,有省略……

181121 Jun 2011 11:001

181221 Jun 2011 12:001

181321 Jun 2011 13:001

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的限制约束,而且灵活度高。本篇记录,权当备忘。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读