Oracle从10G开始引入AWR对数据库的状态进行统计和信息收集。
AWR使用数个表来存储采集的统计数据。
收集信息所在表空间:SYSAUX
模式:SYS
对象名:以WRM$_ 和WRH$_开头
WRM$_ (元数据)
WRH$_ (实际采集的历史数据,H:Historical)
另外还在这些表上构建了几种前缀为DBA_HIST_的视图,视图的名称直接与表相关。如DBA_HIST_SYSMETRIC_SUMMARY是WRH$_SYSMETRIC_SUMMARY表上构建出来的,也可以通过存储表编写自己的性能诊断视图。
AWR相关的参数
SQL> col name for a40 SQL> col value for a30 SQL> select name,value from v$parameter where name like 'statistics_level%'; NAME VALUE ---------------------------------------- ------------------------------ statistics_level TYPICAL
在10g后statistics_level参数默认为typical状态,在该状态下AWR收集功能时激活的,但如果将statistics_level设置为basic,则会禁用掉10g的如下新功能:
ASH(Active Session History)
ASSM(Automatic Shared Memory Management)
AWR(Automatic Workload Repository)
ADDM(Automatic Database Diagnostic Monitor)
先来查看一下当前的AWR保存策略:
SQL> col snap_interval for a20 SQL> col retention for a20 SQL> select * from dba_hist_wr_control; DBID SNAP_INTERVAL RETENTION TOPNSQL ---------- -------------------- -------------------- ------------------------------ 1394247230 +00000 01:00:00.0 +00008 00:00:00.0 DEFAULT
可以看到快照间隔是1小时,保留8天的快照
调整AWR配置
通过dbms_workload_repository包进行配置
修改AWR快照间隔及保留时间:
exec dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>5*24*60)
关闭AWR
exec dbms_workload_repository.modify_snapshot_settings(interval=>0)
exec dbms_workload_repository.create_snapshot()
查看快照信息
SELECT SAMPLE_ID,SAMPLE_TIME,IS_AWR_SAMPLE,SQL_ID FROM V$ACTIVE_SESSION_HISTORY
手工删除指定范围快照
exec DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(low_snap_id=>973, high_snap_id=>999, dbid=>1394247230)
exec dbms_workload_repository.create_baseline(start_snap_id=>1003, end_snap_id=>1013, 'app_baseline_1')
删除基线
exec DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(baseline_name=>'app_baseline_1', cascade=>FALSE)
exec DBMS_SWRF_INTERNAL.AWR_EXTRACT(dmpfile=>'awr_data.dmp', dmpdir=>'BACKUPDIR', bid=>674, eid=>834,dbid=>1394247230)
exec DBMS_SWRF_INTERNAL.AWR_LOAD(SCHNAME=>'SCOTT',dmpfile=>'awr_data.dmp', dmpdir=>'BACKUPDIR')
exec DBMS_SWRF_INTERNAL.MOVE_TO_AWR (SCHNAME =>'HR');
AWR报告的收集:
SQL> @?/rdbms/admin/awrrpt.sql Current Instance ~~~~~~~~~~~~~~~~ DB Id DB Name Inst Num Instance ----------- ------------ -------- ------------ 1394247230 ORCL 1 orcl 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 Instances in this Workload Repository schema ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DB Id Inst Num DB Name Instance Host ------------ -------- ------------ ------------ ------------ * 1394247230 1 ORCL orcl 021Y-SH-BKAP Using 1394247230 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 Listing the last day's Completed Snapshots Snap Instance DB Name Snap Id Snap Started Level ------------ ------------ --------- ------------------ ----- orcl ORCL 822 02 Feb 2015 00:00 1 823 02 Feb 2015 01:01 1 824 02 Feb 2015 02:00 1 825 02 Feb 2015 03:00 1 826 02 Feb 2015 04:00 1 827 02 Feb 2015 05:00 1 828 02 Feb 2015 06:00 1 829 02 Feb 2015 07:00 1 830 02 Feb 2015 08:00 1 831 02 Feb 2015 09:00 1 832 02 Feb 2015 10:00 1 833 02 Feb 2015 11:00 1 834 02 Feb 2015 12:00 1 835 02 Feb 2015 13:00 1 Specify the Begin and End Snapshot Ids ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter value for begin_snap: ......
收集完成后可以通过浏览器查看