oracle

关注公众号 jb51net

关闭
首页 > 数据库 > oracle > Oracle AWR报告生成与分析

Oracle数据库AWR报告的生成步骤与分析方法

作者:晴天¥

本文介绍了在Oracle数据库中生成AWR报告的基本步骤和方法,以及分析AWR报告的五步法:1 看整体负载;2 查看等待事件;3 了解SQL统计;4 调查时间模型;5 分析操作系统和内存,需要的朋友可以参考下

Oracle中要想生成 AWR(Automatic Workload Repository)报告,最常用的方法是通过 Oracle 自带的命令行脚本。AWR 报告是分析数据库性能、定位瓶颈的利器,生成步骤并不复杂,主要分为确认权限执行脚本选择范围三步。

一、登录数据库

首先,你需要以具有足够权限的数据库管理员账号登录到数据库所在的服务器,并连接到数据库。

打开终端,输入以下命令登录到数据库服务器,并使用 sqlplus 工具以 sysdba(系统管理员)身份连接:

# 切换到 oracle 用户 (通常为 oracle)
su - oracle
# 以 sysdba 身份登录
sqlplus / as sysdba

二、执行 AWR 报告生成脚本

登录成功后,执行 Oracle 内置的报告生成脚本 awrrpt.sql 。这个脚本会引导你一步步完成报告的生成。

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

命令解释@表示执行一个 SQL 脚本,? 是 $ORACLE_HOME 路径的简写。因此,这条命令会完整地定位到该脚本并执行它。

三、选择报告类型与时间范围

脚本执行后,系统会提示你进行几个简单的选择,按需输入即可

3.1.选择报告格式

Enter value for report_type: html
        1.html:生成HTML格式,图形化界面,推荐选择
        2.text:生成纯文本格式。

3.2.选择时间范围(最关键的一步)

AWR 基于快照来记录性能数据。你需要选择开始快照结束快照的 ID,报告将展示这两个时间点之间的性能情况。

系统会列出最近可用的快照及其对应的时间,例如:

Snap     Instance     Snap Started
-------- ------------ -----------------------
   123    ORCL        09 Apr 2026 10:00
   124    ORCL        09 Apr 2026 11:00
   125    ORCL        09 Apr 2026 12:00

指定开始时间:输入你分析时间段的起始快照 ID,例如 124

指定结束时间:输入结束快照 ID,例如 125

注意:AWR 默认每小时自动生成一次快照。如果你的数据库是新安装的,可能需要等待一段时间才能有足够的数据来生成有意义的报告

3.3.指定AWR报告名称

Enter value for report_name: awr_report_20260409.html

整体示例:

[oracle@rac01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Apr 9 14:41:40 2026
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> @?/rdbms/admin/awrrpt.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: html
old   1: select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual
new   1: select 'Type Specified: ',lower(nvl('html','html')) report_type from dual
Type Specified:  html
old   1: select '&&report_type' report_type_def from dual
new   1: select 'html' report_type_def from dual
old   1: select '&&view_loc' view_loc_def from dual
new   1: select 'AWR_PDB' view_loc_def from dual
Current Instance
~~~~~~~~~~~~~~~~
DB Id          DB Name        Inst Num       Instance       Container Name
-------------- -------------- -------------- -------------- --------------
 1747225139     ORCL                        1 orcl           orcl
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DB Id      Inst Num   DB Name      Instance     Host
------------ ---------- ---------    ----------   ------
* 1747225139     1      ORCL         orcl         rac01.exampl
Using 1747225139 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: 1
Listing the last day's Completed Snapshots
Instance     DB Name      Snap Id       Snap Started    Snap Level
------------ ------------ ---------- ------------------ ----------
orcl         ORCL                57  09 Apr 2026 12:56    1
                                 58  09 Apr 2026 14:00    1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 57
Begin Snapshot Id specified: 57
Enter value for end_snap: 58
End   Snapshot Id specified: 58
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_57_58.html.  To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: awr_report_20260409.html
Using the report name awr_report_20260409.html
<html lang="en"><head><title>AWR Report for DB: ORCL, Inst: orcl, Snaps: 57-58</title>
............
............
............
End of Report
</body></html>
Report written to awr_report_20260409.html
SQL>

四、获取报告文件

完成上述选择后,脚本会自动生成报告并保存在你当前登录的目录下。

你可以在当前 sqlplus 所在的路径下找到生成的报告文件(例如 awr_report_20260409.html),使用 ls 命令确认后,通过远程工具将其下载到本地,用浏览器打开即可查看。

五、分析AWR性能报告

5.1.AWR 报告分析入门:五步法

分析一份有实际负载的 AWR 报告,通常遵循以下五个核心步骤。你可以把这个方法套用到未来的任何报告分析中。

Elapsed:消耗

parse:解析

第一步:看整体负载 —— “数据库忙不忙?”

分析方法:

DB Time 是数据库处理用户请求花费的总时间。将它除以 Elapsed Time(快照时长),可以算出平均活动会话数。

在我的AWR报告中分析:DB Time = 0,则平均活动会话 = 0。结论是数据库处于完全空闲状态

第二步:看等待事件 —— “瓶颈在哪里?”

第三步:看 SQL 统计 —— “是哪些 SQL 在消耗资源?”

第四步:看时间模型 —— “时间都花在哪儿了?”

第五步:看操作系统和内存 —— “硬件资源够不够?”

分析方法:

以上就是Oracle数据库AWR报告的生成步骤与分析方法的详细内容,更多关于Oracle AWR报告生成与分析的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:
阅读全文