Oracle AWR(Automatic Workload Repository) 说明
http://blog.youkuaiyun.com/tianlesoftware/article/details/4682300
一. AWR说明
Oracle 10g之前对数据库做性能检测使用statspack工具。关于statspack的说明,参考我的Blog:
statspack安装使用和report分析
http://blog.youkuaiyun.com/tianlesoftware/archive/2009/10/16/4682329.aspx
Oracle Database 10g提供了一个新的工具:(AWR:Automatic Workload Repository)。Oracle建议用户用这个取代Statspack。AWR实质上是一个Oracle的内置工具,它采集与性能相关的统计数据,并从那些统计数据中导出性能量度,以跟踪潜在的问题。
与Statspack不同,快照由一个称为MMON的新的后台进程及其从进程自动地每小时采集一次。为了节省空间,采集的数据在7天后自动清除。快照频率和保留时间都可以由用户修改。它产生两种类型的输出:文本格式(类似于Statspack报表的文本格式但来自于AWR信息库)和默认的HTML格式(拥有到部分和子部分的所有超链接),从而提供了非常用户友好的报表。
AWR使用几个表来存储采集的统计数据,所有的表都存储在新的名称为SYSAUX的特定表空间中的SYS模式下,并且以WRM$_*和WRH$_*的格式命名。前一种类型存储元数据信息(如检查的数据库和采集的快照),后一种类型保存实际采集的统计数据。H代表“历史数据(historical)”而M代表“元数据(metadata)”。
在这些表上构建了几种带前缀DBA_HIST_的视图,这些视图可以用来编写您自己的性能诊断工具。视图的名称直接与表相关;例如,视图DBA_HIST_SYSMETRIC_SUMMARY是在WRH$_SYSMETRIC_SUMMARY表上构建的。
注意一点:
statistics_level默认是typical,在10g中表监控是激活的,强烈建议在10g中此参数的值是typical。如果STATISTICS_LEVEL设置为basic,不仅不能监控表,而且将禁掉如下一些10g的新功能:
ASH(Active Session History)
ASSM(Automatic Shared Memory Management)
AWR(Automatic Workload Repository)
ADDM(Automatic Database Diagnostic Monitor)
在Oracle 11gR2里禁用的功能如下:
STATISTICS_LEVEL
specifies the level of collection for database and operating system statistics. The Oracle Database collects these statistics for a variety of purposes, including making self-management decisions.
The default setting ofTYPICAL
ensures collection of all major statistics required for database self-management functionality and provides best overall performance. The default value should be adequate for most environments.
When theSTATISTICS_LEVEL
parameter is set toALL
, additional statistics are added to the set of statistics collected with theTYPICAL
setting. The additional statistics are timed OS statistics and plan execution statistics.
Setting theSTATISTICS_LEVEL
parameter toBASIC
disables the collection of many of the important statistics required by Oracle Database features and functionality, including:
-
Automatic Workload Repository (AWR) Snapshots
-
Automatic Database Diagnostic Monitor (ADDM)
-
All server-generated alerts
-
Automatic SGA Memory Management
-
Automatic optimizer statistics collection
-
Object level statistics
-
End to End Application Tracing (
V$CLIENT_STATS
) -
Database time distribution statistics (
V$SESS_TIME_MODEL
andV$SYS_TIME_MODEL
) -
Service level statistics
-
Buffer cache advisory
-
MTTR advisory
-
Shared pool sizing advisory
-
Segment level statistics
-
PGA Target advisory
-
Timed statistics
-
Monitoring of statistics
二.AWR使用
SQL>@?/rdbms/admin/awrrpt.sql
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'
输入report_type的值:
Type Specified:html
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.
输入num_days的值:1
Listing the last day's Completed Snapshots
Snap
InstanceDB NameSnap IdSnap StartedLevel
------------ ------------ --------- ------------------ -----
orcl10gORCL10G142 03 7月2009 08:111
143 03 7月2009 09:001
144 03 7月2009 10:001
145 03 7月2009 11:001
146 03 7月2009 12:011
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入begin_snap的值:142
Begin Snapshot Id specified: 142
输入end_snap的值:146
EndSnapshot Id specified: 146
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_142_146.html.To use this name,
press <return> to continue, otherwise enter an alternative.
输入report_name的值:D:/awrrpt_1_142_146.html
Report written to D:/awrrpt_1_142_146.html
三.AWR操作
3.1.查看当前的AWR保存策略
SQL> col SNAP_INTERVAL format a20
SQL> col RETENTION format a20
SQL> select * from dba_hist_wr_control;
DBID SNAP_INTERVALRETENTIONTOPNSQL
---------- -------------------- -------------------- ----------
262089084 +00000 01:00:00.0+00007 00:00:00.0DEFAULT
以上结果表示,每小时产生一个SNAPSHOT,保留7天。
3.2.调整AWR配置
AWR配置都是通过dbms_workload_repository包进行配置。
3.2.1调整AWR产生snapshot的频率和保留策略,如将收集间隔时间改为30分钟一次。并且保留5天时间(单位都是分钟):
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>30, retention=>5*24*60);
3.2.2关闭AWR,把interval设为0则关闭自动捕捉快照
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>0);
3.2.3手工创建一个快照
SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT();
3.2.4查看快照
SQL> select * from sys.wrh$_active_session_history
3.2.5手工删除指定范围的快照
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(low_snap_id => 973, high_snap_id => 999, dbid => 262089084);
3.2.6创建baseline,保存这些数据用于将来分析和比较
SQL> exec dbms_workload_repository.create_baseline(start_snap_id => 1003, end_snap_id => 1013, 'apply_interest_1');
3.2.7删除baseline
SQL> exec DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(baseline_name => 'apply_interest_1', cascade => FALSE);
3.2.8将AWR数据导出并迁移到其它数据库以便于以后分析
SQL> exec DBMS_SWRF_INTERNAL.AWR_EXTRACT(dmpfile => 'awr_data.dmp', mpdir => 'DIR_BDUMP', bid => 1003, eid => 1013);
3.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');
四. AWR报告分析
这部分内容,可以参考statspack,这2个内容都差不多。
statspack安装使用和report分析
http://blog.youkuaiyun.com/tianlesoftware/archive/2009/10/16/4682329.aspx
4.1 SQL ordered by Elapsed Time
记录了执行总和时间的TOP SQL(请注意是监控范围内该SQL的执行时间总和,而不是单次SQL执行时间Elapsed Time = CPU Time + Wait Time)。
Elapsed Time(S):SQL语句执行用总时长,此排序就是按照这个字段进行的。注意该时间不是单个SQL跑的时间,而是监控范围内SQL执行次数的总和时间。单位时间为秒。Elapsed Time = CPU Time + Wait Time
CPU Time(s):为SQL语句执行时CPU占用时间总时长,此时间会小于等于Elapsed Time时间。单位时间为秒。
Executions:SQL语句在监控范围内的执行次数总计。
Elap per Exec(s):执行一次SQL的平均时间。单位时间为秒。
% Total DB Time:为SQL的Elapsed Time时间占数据库总时间的百分比。
SQL ID:SQL语句的ID编号,点击之后就能导航到下边的SQL详细列表中,点击IE的返回可以回到当前SQL ID的地方。
SQL Module:显示该SQL是用什么方式连接到数据库执行的,如果是用SQL*Plus或者PL/SQL链接上来的那基本上都是有人在调试程序。一般用前台应用链接过来执行的sql该位置为空。
SQL Text:简单的sql提示,详细的需要点击SQL ID。
4.2 SQL ordered by CPU Time:
记录了执行占CPU时间总和时间最长的TOP SQL(请注意是监控范围内该SQL的执行占CPU时间总和,而不是单次SQL执行时间)。
4.3 SQL ordered by Gets:
记录了执行占总buffer gets(逻辑IO)的TOP SQL(请注意是监控范围内该SQL的执行占Gets总和,而不是单次SQL执行所占的Gets)。
4.4 SQL ordered by Reads:
记录了执行占总磁盘物理读(物理IO)的TOP SQL(请注意是监控范围内该SQL的执行占磁盘物理读总和,而不是单次SQL执行所占的磁盘物理读)。
4.5 SQL ordered by Executions:
记录了按照SQL的执行次数排序的TOP SQL。该排序可以看出监控范围内的SQL执行次数。
4.6 SQL ordered by Parse Calls:
记录了SQL的软解析次数的TOP SQL。说到软解析(soft prase)和硬解析(hard prase),就不能不说一下Oracle对sql的处理过程。
4.7 SQL ordered by Sharable Memory:
记录了SQL占用library cache的大小的TOP SQL。Sharable Mem (b):占用library cache的大小,单位是byte。
4.8 SQL ordered by Version Count:
记录了SQL的打开子游标的TOP SQL。
4.9 SQL ordered by Cluster Wait Time:
记录了集群的等待时间的TOP SQL