AWR (Automatic Workload Repository) 是自动负载信息库的英文缩写,AWR报告是Oracle 10g以后版本提供的一种性能收集和分析工具,能提供一个时间段内整个系统资源使用情况的报告,通过报告可以了解一个系统的整个运行情况。
生成AWR报告
-
切换用户
使用oralce用户登陆操作系统,如果不知道oracle用户密码,可从root用户
su - oracle
:server01:root:/>whoami root server01:root:/>su - oracle server01:oracle:/home/oracle>whoami oracle server01:oracle:/home/oracle>
-
sqlplus连接数据库
在oracle用户下执行
sqlplus / as sysdba
命令,连接到oracle数据库:server01:oracle:/home/oracle>sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 12 00:01:02 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
-
导出当前实例的AWR报告
在sqlplus中执行
@?/rdbms/admin/awrrpt.sql
:SQL> @?/rdbms/admin/awrrpt.sql Current Instance ~~~~~~~~~~~~~~~~ DB Id DB Name Inst Num Instance ----------- ------------ -------- ------------ 919662622 DEVDB 1 devdb Specify the Report Type ~~~~~~~~~~~~~~~~~~~~~~~
-
输入导出报告的格式
在执行@?/rdbms/admin/awrrpt.sql命令后,会提示输入导出报告的格式,默认格式为html,如果想导出html格式,直接Enter即可:
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:
-
输入导出天数
根据需要,输入导出的报告的具体天数,即当前时间N天之内的所有信息:
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:
-
输入要导出的snap的开始ID
在输入要导出的天数之后,oracle会列出所有满足预期天数的snap的信息,根据需要,输入snap的开始ID:
Listing the last 2 days of Completed Snapshots Instance DB Name Snap Id Snap Started Snap Level ------------ --------- --------- ------------------ ----- devdb DEVDB 3151 11 Dec 2019 00:00 1 3152 11 Dec 2019 01:00 1 3153 11 Dec 2019 02:00 1 3154 11 Dec 2019 03:00 1 3155 11 Dec 2019 04:00 1 3156 11 Dec 2019 05:00 1 3157 11 Dec 2019 06:00 1 3158 11 Dec 2019 07:00 1 3159 11 Dec 2019 08:00 1 3160 11 Dec 2019 09:00 1 3161 11 Dec 2019 10:00 1 3162 11 Dec 2019 11:00 1 3163 11 Dec 2019 12:00 1 3164 11 Dec 2019 13:00 1 3165 11 Dec 2019 14:00 1 3166 11 Dec 2019 15:00 1 3167 11 Dec 2019 16:00 1 3168 11 Dec 2019 17:00 1 3169 11 Dec 2019 18:00 1 3170 11 Dec 2019 19:00 1 3171 11 Dec 2019 20:00 1 3172 11 Dec 2019 21:00 1 3173 11 Dec 2019 22:00 1 3174 11 Dec 2019 23:00 1 3175 12 Dec 2019 00:00 1 Specify the Begin and End Snapshot Ids ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter value for begin_snap:
-
输入要导出的snap的截止ID
输入开始ID之后,会提示输入截止ID,根据需要输入截止ID:
Enter value for end_snap:
-
设置导出的报告名称
导出报告时,如果需要设置导出的报告名称,可根据提示进行修改:
Specify the Report Name ~~~~~~~~~~~~~~~~~~~~~~~ The default report file name is awrrpt_1_3151_3175.html. To use this name, press <return> to continue, otherwise enter an alternative. Enter value for report_name:
-
查看报告
输入报告名称之后并敲击回车之后,oracle会自动生成AWR报告,可退出sqlplus进行查看:SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options server01:oracle:/home/oracle>ls -lrt total 12544 drwxr-xr-x 4 root system 256 Jul 02 1972 app -rw-r--r-- 1 oracle dba 25178 Jul 02 1972 db.rsp -rw-r--r-- 1 oracle dba 8 Jul 03 1972 #UNTITLED# -rw-r----- 1 oracle dba 4950061 Jul 06 1972 core -rw-r----- 1 oracle dba 289692 Jul 29 22:31 install2019-07-29_22-17-53.log drwxr-xr-x 2 oracle dba 256 Aug 01 00:40 scripts -rw-r--r-- 1 oracle dba 594527 Dec 11 22:37 test.html -rw-r--r-- 1 oracle dba 545490 Dec 12 00:51 awr.html