手工生成AWR报告方法记录

来源:互联网 发布:h5转盘抽奖源码 编辑:程序博客网 时间:2024/04/30 04:00

Oracle 在10g以前的使用的是Statspack做性能故障诊断的。Oracle Database 10g 提供了一个显著改进的工具:自动工作负载信息库 (AWR)。AWR 和数据库一起安装。数据库装好后,快照由一个称为 MMON 的新的后台进程及其从进程自动地每小时采集一次(snap)

1. 查看当前的AWR保存策略、设置:快照间隔、保存时间。

SQL> col SNAP_INTERVAL format a20
SQL> col RETENTION format a20
SQL> select * from dba_hist_wr_control;
      DBID SNAP_INTERVAL        RETENTION            TOPNSQL
---------- -------------------- -------------------- ----------
3178546677 +00000 01:00:00.0    +00007 00:00:00.0    DEFAULT

以上结果表示,每小时产生一个SNAPSHOT,保留7天。
2. 调整AWR配置,修改快照间隔和保存时间等。AWR配置都是通过dbms_workload_repository包进行配置。
2.1 调整AWR产生snapshot的频率和保留策略,如将收集间隔时间改为30 分钟一次。并且保留5天时间(单位都是分钟):
    SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30, retention=>5*24*60);
    设置快照时间间隔为 20 分钟,保留时间为两天 -- 您可以发出以下命令。参数以分钟为单位。
    SQL> exec dbms_workload_repository.modify_snapshot_settings ( interval => 20, retention => 2*24*60 );

2.2 关闭AWR,把interval设为0则关闭自动捕捉快照
    SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>0);
2.3 手工创建一个快照
    SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT();
         exec dbms_workload_repository.create_snapshot;

2.4 查看快照
    SQL> select * from sys.wrh$_active_session_history
    SQL> select count(*),max(snap_id) from wrh$_active_session_history;

2.5 手工删除指定范围的快照
    SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(low_snap_id => 973, high_snap_id => 999, dbid => 262089084);

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

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

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

2.9 迁移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');


3. 性能测试及生成awr报告
3.1 登陆Oracle数据库:
   sqlplus / as sysdba

3.2 在sqlplus中,以sys用户运行下面的命令,生成第一份性能数据快照:
   exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT (flush_level=>'ALL');

3.3 运行你找到的所有或很多性能较差的应用或SQL,让系统压力始终处于比较高的状态(如CPU或IO的使用),并保持此状态达到半小时到1小时

3.4 在sqlplus中,以sys用户再次运行下面的命令,生成第二份性能数据快照:
    exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT (flush_level=>'ALL');

3.5 在sqlplus中,以sys用户运行下面的命令,以产生性能报告:
    @?/rdbms/admin/awrrpt.sql

根据提示,选择上面生成的2个性能数据快照,最后会生成一个最终的AWR性能报告。

a) 出现选择awr的输出格式界面(默认选HTML比较直观)
-----------------------------------------------
Current Instance
 ~~~~~~~~~~~~~~~~

 DB Id DB Name Inst Num Instance
 ----------- ------------ -------- ------------
 2566595041 samp 2 samp2


 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: html

 Type Specified: html

 -----------------------------------------------
b) 选择采集日期间隔(下述samp1samp2是RAC节点的两个实例)
-----------------------------------------------
Instances in this Workload Repository schema
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 DB Id Inst Num DB Name Instance Host
 ------------ -------- ------------ ------------ ------------
 * 2566595041 2 samp samp2 p650b
   2566595041 1 samp samp1 p650a

 Using 2566595041 for database Id
 Using 2 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

 ------------------------------------------------
c) 选择开始和结束采集点30132-30148
 ------------------------------------------------
 Listing the last day's Completed Snapshots

 Snap
 Instance DB Name Snap Id Snap Started Level
 ------------ ------------ --------- ------------------ -----
 samp2 samp 30132 13 Aug 2010 00:00 1
 30133 13 Aug 2010 01:00 1
 30134 13 Aug 2010 02:00 1
 30135 13 Aug 2010 03:00 1
 30136 13 Aug 2010 04:00 1
 30137 13 Aug 2010 05:00 1
 30138 13 Aug 2010 06:00 1
 30139 13 Aug 2010 07:00 1
 30140 13 Aug 2010 08:00 1
 30141 13 Aug 2010 09:00 1
 30142 13 Aug 2010 10:00 1
 30143 13 Aug 2010 11:00 1
 30144 13 Aug 2010 12:00 1
 30145 13 Aug 2010 13:00 1
 30146 13 Aug 2010 14:00 1
 30147 13 Aug 2010 15:00 1
 30148 13 Aug 2010 16:00 1

 Specify the Begin and End Snapshot Ids
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Enter value for begin_snap: 30132
 Begin Snapshot Id specified: 30132

 Enter value for end_snap:30148
 End Snapshot Id specified: 30148
 ------------------------------------------------
d) 指定输出地址和名称/tmp/awrrpt_2_30132_30148.html
 ------------------------------------------------
 Specify the Report Name
 ~~~~~~~~~~~~~~~~~~~~~~~
 The default report file name is awrrpt_2_30132_30148.html. To use this name,
 press <return> to continue, otherwise enter an alternative.

 Enter value for report_name:/tmp/awrrpt_2_30132_30148.html
 ------------------------------------------------
e) 生成过程----屏幕打印一堆html代码
------------------------------------------------
Using the report name /tmp/awrrpt_2_30132_30148.html

 <HTML><HEAD><TITLE>AWR Report</TITLE><style type="text/css">body.awr {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;color:black; background:White;}

f) 结束生成过程
------------------------------------------------
End of Report
 </BODY></HTML>
 Report written to /tmp/awrrpt_2_30132_30148.html
 SQL>
 ------------------------------------------------
g) 到指定目录下/tmp/取出awrrpt_2_30132_30148.html,在IE等浏览器打开就可以阅读了。

 

0 0
原创粉丝点击