AWR使用学习

来源:互联网 发布:ubuntu 14 trusty 编辑:程序博客网 时间:2024/04/28 08:59

Oracle Database 10g 提供了一个替代Statspack的工具:自动工作负载信息库 (AWR:Automatic Workload Repository)。相对于Statspack需要进行初始设置才能工作来说,AWR无需初始设置,数据库安装时默认已经开启的。

AWR 实质上是一个 Oracle 的内置工具,它采集与性能相关的统计数据,并从那些统计数据中导出性能量度,以跟踪潜在的问题,快照由一个称为 MMON 的新的后台进程及其从进程默认自动地每小时采集一次,默认采集的数据在 7 天后自动清除。快照频率和保留时间都可以由用户修改。它产生两种类型的输出:文本格式(类似于 Statspack 报表的文本格式但来自于 AWR 信息库)和默认的 HTML 格式(拥有到部分和子部分的所有超链接),从而提供了非常用户友好的报表。
AWR 使用几个表来存储采集的统计数据,所有的表都存储在新的名称为 SYSAUX 的特定表空间中的 SYS 模式下,并且以 WRM$_* 和 WRH$_* 的格式命名。前一种类型存储元数据信息(如检查的数据库和采集的快照),后一种类型保存实际采集的统计数据。H 代表“历史数据 (historical)”而 M 代表“元数据 (metadata)”。在这些表上构建了几种带前缀 DBA_HIST_ 的视图,这些视图可以用来编写您自己的性能诊断工具。视图的名称直接与表相关;例如,视图 DBA_HIST_SYSMETRIC_SUMMARY 是在WRH$_SYSMETRIC_SUMMARY 表上构建的。

 

一:AWR使用

使用方法很简单,就是直接一个命令即可,中途会提示你输入一些讯息

SQL> @H:/oracle/product/10.2.0/db_1/rdbms/admin/awrrpt.sql;

Current Instance
~~~~~~~~~~~~~~~~

      DBID DB_NAME      INST_ INST_NAME
---------- ------------ ----- ------------
2420544136 MYTEST           1 mytest
rpt_options
---------
0

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'
Type Specified:  html
Cannot SET TRIMSPOOL
Cannot SET UNDERLINE


Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DBBID        INSTT DBB_NAME     INSTT_NAME   HOST
------------ ----- ------------ ------------ ------------
* 2420544136     1 MYTEST       mytest       SHPC09191

Using 2420544136 for database Id
Using 1 for instance number
dbid
---------
2420544136
inst_num
---------
1
inst_num
---------
1
dbid
---------
2420544136
max_snap_time
---------
16/07/2010


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.


Listing the last 5 days of Completed Snapshots

INST_NAME    DB_NAME       SNAP_ID SNAPDAT            LV
------------ ------------ -------- ------------------ --
mytest       MYTEST             35 14 7月  2010 10:38  1
mytest       MYTEST             36 14 7月  2010 12:00  1
mytest       MYTEST             37 14 7月  2010 13:00  1
mytest       MYTEST             38 14 7月  2010 14:00  1
mytest       MYTEST             39 14 7月  2010 15:00  1
mytest       MYTEST             40 14 7月  2010 16:00  1
mytest       MYTEST             41 14 7月  2010 17:00  1
mytest       MYTEST             42 14 7月  2010 18:01  1
mytest       MYTEST             43 15 7月  2010 16:01  1
mytest       MYTEST             44 15 7月  2010 17:07  1
mytest       MYTEST             45 15 7月  2010 18:00  1
mytest       MYTEST             46 16 7月  2010 14:15  1
mytest       MYTEST             47 16 7月  2010 15:00  1
mytest       MYTEST             48 16 7月  2010 16:00  1
mytest       MYTEST             49 16 7月  2010 17:00  1
mytest       MYTEST             50 16 7月  2010 18:00  1
dbid
---------
2420544136
inst_num
---------
1
max_snap_time
---------
16/07/2010


Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Begin Snapshot Id specified: 47

End   Snapshot Id specified: 50

bid
---------
47
eid
---------
50

inst_num
---------
1
dbid
---------
2420544136
bid
---------
47
eid
---------
50
Cannot SET TRIMSPOOL
Cannot SET UNDERLINE

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_47_50.html.  To use this name,
press <return> to continue, otherwise enter an alternative.

Using the report name awrrpt_1_47_50.html
Started spooling to C:/Program Files/PLSQL Developer/awrrpt_1_47_50.html

 

 

.......................................

 


End of Report
</BODY></HTML>
dbid
---------
2420544136
inst_num
---------
1
bid
---------
47
eid
---------
50
rpt_options
---------
0
Stopped spooling to C:/Program Files/PLSQL Developer/awrrpt_1_47_50.html
Report written to awrrpt_1_47_50.html.

 

 

根基提示打开C:/Program Files/PLSQL Developer/awrrpt_1_47_50.html
即可查看相应的统计结果

 

二:AWR的其他说明

 

查看当前快照策略

SQL> select * from dba_hist_wr_control;

      DBID SNAP_INTERVAL                RETENTION           TOPNSQL
---------- ---------------------------- ------------------- ----------
2420544136 +00000 01:00:00.0            +00007 00:00:00.0   DEFAULT

 

 

调整AWR配置
AWR配置都是通过dbms_workload_repository包进行配置。
调整AWR产生snapshot的频率和保留策略,如将收集间隔时间改为2小时一次。并且保留5天时间(单位都是分钟):
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>120, retention=>5*24*60);

SQL> select * from dba_hist_wr_control;

      DBID SNAP_INTERVAL                RETENTION           TOPNSQL
---------- ---------------------------- ------------------- ----------
2420544136 +00000 02:00:00.0            +00005 00:00:00.0   DEFAULT


关闭AWR,把interval设为0则关闭自动捕捉快照
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>0);

 

查看快照
SQL> select * from sys.wrh$_active_session_history

手工创建一个快照
SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT();

手工删除指定范围的快照
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(low_snap_id => 1, high_snap_id => 30, dbid => 2420544136);


创建baseline,保存这些数据用于将来分析和比较
SQL> exec dbms_workload_repository.create_baseline(start_snap_id => 1003, end_snap_id => 1013, 'apply_interest_1');


删除baseline
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(baseline_name => 'apply_interest_1', cascade => FALSE);


将AWR数据导出并迁移到其它数据库以便于以后分析
SQL> exec DBMS_SWRF_INTERNAL.AWR_EXTRACT(dmpfile => 'awr_data.dmp', mpdir => 'DIR_BDUMP', bid => 1003, eid => 1013);

迁移AWR数据文件到其他数据库
SQL> exec DBMS_SWRF_INTERNAL.AWR_LOAD(SCHNAME => 'AWR_TEST', dmpfile => 'awr_data.dmp', dmpdir => 'DIR_BDUMP');

把AWR数据转移到SYS模式中:
SQL> exec DBMS_SWRF_INTERNAL.MOVE_TO_AWR (SCHNAME => 'TEST');