之前工作经常搜集AWR日志,但是因工作环境的调整,6年下来的笔记都无法带出来,只能回忆一些和找一些网上的信息整理了。
前提条件
数据库为Oracle 10g以上版本。
背景信息
Oracle默认快照1小时生成一次、保持7天,可以根据需要调整快照生成的频率、保持时长。如果要手工生成快照,则用~> sqlplus / as sysdba;登录数据库执行命令:
SQL> exec dbms_workload_repository.create_snapshot();
操作步骤
步骤 1 以oracle用户登录操作系统。
步骤 2 登录数据库。
~> sqlplus / as sysdba;
登录成功后,返回信息如下:
SQL*Plus: Release 11.1.0.7.0 - Production on Mon Jul 22 09:52:46 2013
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
步骤 3 生成AWR报表。
1. 开始收集AWR报表
SQL> @?/rdbms/admin/awrrpt.sql;
说明:
对某些系统,@特殊字符前面可能需要转义字符\,才能运行该命令。请运行命令:SQL> \@?/rdbms/admin/awrrpt.sql;
返回信息显示如下:
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
4188289306 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'
Enter value for report_type:
1. 输入报表的格式,有HTML格式、TEXT格式,默认HTML格式。
例如输入格式为html,返回信息如下:
Type Specified: html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 4188289306 1 ORA11G ora11g linux_lbi_02
Using 4188289306 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
1. 输入一个天数,Oracle会列出指定天数的所有快照信息。
例如输入一个天数为1,返回信息如下:
Listing the last day's Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
ora11g ORA11G 3166 22 Jul 2013 00:00 1
3167 22 Jul 2013 01:00 1
3168 22 Jul 2013 02:00 1
3169 22 Jul 2013 03:00 1
3170 22 Jul 2013 04:00 1
3171 22 Jul 2013 05:00 1
3172 22 Jul 2013 06:00 1
3173 22 Jul 2013 07:00 1
3174 22 Jul 2013 08:00 1
3175 22 Jul 2013 09:00 1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap:
1. 输入起始snap Id和结束snap Id,收集两个时刻间段的数据库性能数据。
起始snap Id和结束snap Id这两个时间段之间,不能关闭或启动数据库,否则会报错。
注意:
例如输入起始snap Id为3166,结束snap Id为3168,返回信息如下:
Specify the Begin and End Snapshot Ids
Enter value for begin_snap: 3166
Begin Snapshot Id specified: 3166
Enter value for end_snap: 3168
End Snapshot Id specified: 3168
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_3166_3168.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name:
2. 输入报表名
默认以snap Id命名,可以不输入。
如下所示为生成的AWR报表样例:
Report written to awrrpt_1_3166_3168.html
步骤 1 如果没指定目录和文件名,生成的AWR报表在当前目录,执行如下命令查看。
SQL> host
~> ls
返回信息显示如下:
awrrpt_1_3166_3168.html
----结束