首页 » ORACLE » Know More about Oracle AWR

Know More about Oracle AWR

Statspack 引入从8.1.7,AWR 到Oracle 10g才引入,两个非常的像都是用于oracle性能分析,一段时间以来,Oracle在此领域的解决方案一直是其内置工具Statspack。Oracle数据库10g进行了重大改进:自动工作量存储库(AWR),但是当前对于dataguard性能的分析还是需要statspack。AWR与数据库一起安装,不仅捕获统计信息,还捕获捕获的指标。

AWR保留设置和数据收集频率

默认情况下,AWR历史记录会保留7天,默认情况下,每小时会在AWR存储库表中收集一次数据。

当前的快照保留设置和数据收集频率可以通过下面显示的查询来确定。请注意,在这种情况下,将显示7天1小时的默认设置。

SQL> select to_char(snap_interval,'DD'),to_char(retention,'DD') FROM dba_hist_wr_control;

TO_CHAR(SNAP_INTER TO_CHAR(RETENTION,
------------------ ------------------
+00000 01:00:00.0 +00007 00:00:00.0;

AWR收集关于该特定数据库的操作统计信息和其他统计信息,AWR的采样工作由后台进程MMON每60分钟执行一次,Oracle以固定的时间间隔(默认为每小时一次)为其所有重要统计信息和负载信息执行一次快照,并将这些快照存储在AWR中。这些信息在AWR中保留给定的时间(默认为一周),然后被清除。执行快照的频率及其保持时间都可以自定义,以满足不同环境的独特需要。

要更改设置(例如,对于20分钟的快照间隔和两天的保留期),您将发出以下命令。以分钟为单位指定参数。

begin
dbms_workload_repository.modify_snapshot_settings (
interval => 20,
retention => 2*24*60
);
end;

AWR TABLES

  1. Metadata (WRM$)
  2. Historical data (WRH$)
  3. AWR tables related to advisor functions (WRI$)
  4. Oracle 11g New Features About Workload Capture and Workload Replay tables (WRR$)

Workload Repository Reports

Oracle提供了两个主要脚本来生成工作负载存储库报告(awrrpt.sql和awrrpti.sql)。它们的格式类似于statspack报告,并提供HTML或纯文本格式(12c以后提供了更加可视化的ahtml)的选项。这两个报告给出了基本相同的输出,但是awrrpti.sql允许您选择一个实例。可以如下生成报告:

@$ORACLE_HOME/rdbms/admin/awrrpt.sql
@$ORACLE_HOME/rdbms/admin/awrrpti.sql

There are other scripts too, here is the full list:

REPORT NAME                                   SQL Script 
Automatic Workload Repository Report          awrrpt.sql 
Automatic Database Diagnostics Monitor Report addmrpt.sql 
ASH Report                                    ashrpt.sql 
AWR Diff Periods Report                       awrddrpt.sql 
AWR Single SQL Statement Report               awrsqrpt.sql 
AWR Global Report                             awrgrpt.sql 
AWR Global Diff Report                        awrgdrpt.sql  

Exporting and Importing AWR snapshot data

AWR数据存储在SYSAUX表空间的WRH $和DBA_HIST表中。如果这些表的大小太大或保留时间增加到默认的7天以上,则可能会对性能产生影响。

一个好的解决方案是拥有一个中央存储库,并使用Oracle提供的awrextr.sql和awrload.sql脚本(可在$ ORACLE_HOME / rdbms / admin目录中找到)来定期将统计AWR数据移动到该中央存储库数据库中。

-- in source db
SQL> @?/rdbms/admin/awrextr.sql
-- in target db
SQL>@?/rdbms/admin/awrload.sql
or
using oracle internal package
dbms_swrf_internal.AWR_EXTRACT
DBMS_SWRF_INTERNAL.AWR_LOAD
DBMS_SWRF_INTERNAL.MOVE_TO_AWR
DBMS_SWRF_INTERNAL.CLEAR_AWR_DBID

STATISTICS_LEVEL

AWR的行为受到数据库另外一个重要初始化参数STATISTICS_LEVEL的影响,该参数有3个可选值。

·BASIC:设置为BASIC时,AWR的统计信息收集所有自我调整的特性都被关闭。

·TYPICAL:设置为TYPICAL时,数据库收集部分统计信息,这些信息为典型的数据库监控需要,是数据库的缺省设 置。

·ALL:所有可能的统计信息都被收集。

Monitoring AWR

WRM $ _SNAPSHOT_DETAILS在11.1.0.7数据库中不存在,但在11.2.0.3中存在。如果此对象在某些发行版中不存在,则在执行时,SQL将生成错误。

 col instance_number form 999 head INST 
 col begin_interval_time form a25 
 col flush_elapsed form a17 
 col status form 999 
 col error_count form 999 head ERR 
 col snap_flag form 999 head SNAP 
SQL> select * from 
  (select snap_id, 
  instance_number, 
  begin_interval_time, 
  flush_elapsed, 
  status, 
  error_count, 
  snap_flag 
  from wrm$_snapshot 
  where dbid = (select dbid from v$database) 
  order by snap_id desc) 
  where rownum <= 10 
  order by snap_id 
/

DEBUG TO TRACE FILE

alter session set "_swrf_test_action" = 10; 
alter session set events 'immediate trace name awr_test level 3';

Timing information for each individual table flush

set pagesize 999 
column name format a28 
column time format a29 
variable dbid number 
exec select dbid into :dbid from v$database; 
variable snap_id number 
exec select max(snap_id) into :snap_id from wrm$_snapshot where dbid=:dbid; 
 
select table_name_kewrtb name, end_time-begin_time time 
from wrm$_snapshot_details, x$kewrtb 
where snap_id = :snap_id 
and dbid = :dbid 
and table_id = table_id_kewrtb 
order by table_id;

To investigate the errors, start with the WRM$_SNAP_ERROR table:

SQL> select * from wrm$_snap_error 
  where dbid = (select dbid from v$database) 
  order by snap_id; 

Clean AWR

exec dbms_swrf_internal.unregister_database();
dbms_workload_repository.DROP_SNAPSHOT_RANGE;

Disable Oracle AWR

如果要禁止在Oracle数据库上执行AWR,可以使用以下几种方法将其关闭。如果您不使用AWR数据,为什么要为连续运行和收集未使用的数据而付出代价。我认为最简单的选择首先列出了这些步骤。

1,Set STATISTICS_LEVEL parameter to BASIC.
2,Run the CATNOAWR.sql script to drop the AWR Repository tables. The script calls procedure dbms_swrf_internal.remove_wr_control, which deletes a row relating to your database from the wrm$_wr_control table, and then drops all the AWR tables.
3,Execute DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(interval=>0).By setting the value of the interval as 0, we set the new interval between each snapshot collection as 110 years:
4,Download dbms_awr.plb from Metalink, compile this package and execute the PL/SQL package DBMS_AWR.DISABLE_AWR() [see Metalink note 436386.1].
5,This does not work for an existing database, but does for future databases: Create your own database creation scripts (do not utilize DBCA) and do not execute the CATAWRTB.sql script.
6,_awr_restrict_mode initialization parameter which is set to TRUE and turns off all AWR features in the repository database

Recreate the AWR

由于我们的SYSAUX表空间不断增长,Oracle支持建议我们使用以下步骤重新创建AWR:

alter system set sga_target=0 scope=spfile;
alter system set statistics_level = basic scope=both;
alter system set cluster_database=false;

shutdown immediate

startup restrict
-- in 10g begin ---
@?/rdbms/admin/catnoawr.sql
alter system flush shared_pool;
@?/rdbms/admin/catsvrm.sql --in the script had calls catawrtb.sql
-- in 10g end ---

-- in 11g begin---
SQL> @?/rdbms/admin/catnoawr.sql
SQL> alter system flush shared_pool;
SQL> @?/rdbms/admin/catawr.sql
SQL> @?/rdbms/admin/utlrp.sql
sql> @?/rdbms/admin/execsvrm.sql
-- in 11g end---

Then re-enable the AWR statistics gathering as required, by setting STATISTICS_LEVEL back to its original value, and restart the instance normally

AWR的采样数据存储:

AWR记录的信息还远不止于此,通过系统的自动采样,AWR可以收集数据库运行的各方面统计信息及等待等重要数据, 提供给数据库诊断分析使用。当然AWR的信息需要独立存储,在Oracle 10g中,新增的SYSAUX表空间是这类信息的存储地:

SQL> select occupant_name,occupant_desc,schema_name,space_usage_kbytes/1024 "MB"
 from v$sysaux_occupants
 where occupant_name like '%AWR%';

Tip:
When SYSAUX tablespace is keep growing,you can check the V$SYSAUX_OCCUPANTS View to find out who/what is occupying space in SYSAUX.

打赏

对不起,这篇文章暂时关闭评论。