一.关于ASH

  我们都知道,用户在 ORACLE 数据库中执行操作时,必然要创建相应的连接和会话, 其中,所有当前的会话信息都保存在动态性能视图 V$SESSION 中,通过该视图,DBA 可 以查看用户实际执行的操作,或者当前的等待事件等。通常这部分信息是调优过程中的关键 信息,不过,一旦连接断开。会话信息就会被同时从V$SESSION及其它相关视图中清除, 也就是说,用户执行完操作走人,而你(DBA),如果不能在当前逮到他,过了这点,就不知 道它曾经做过什么了。

  10g 版本中,ORACLE 又新增加了一个视图(其它是若干,不过咱们还是以session 为引 子说):V$ACTIVE_SESSION_HISTORY,看名字就知道,就是活动会话的历史记录.这下,即使用户操作完成后,断开了连接也不怕,因为其会话的情况已经被记录了下来,这项特性 就是 ASH了,全称与视图名相同,正是:ACTIVESESSIONHISTORY。 ASH 每秒钟收集一次当前处于非空闲等待事件的、活动状态的、session 的信息,并保 存在 V$ACTIVE_SESSION_HISTORY视图中,我们(应该以及必须)知道,动态性能视图其 实上是 ORACLE 自行构造的一堆存在于 SGA 内存区的虚表,就是说,ASH 的数据是保存在内存里的,实际上,ORACLE分配给 ASH 的空间并不是无限大(更何况 ORACLE 自身管 理的内存空间也不是无限大),查看 ASH可供使用的内存空间,可以通过如下SQL:

SQL> select pool,name,bytes/1024/1024 Mb From v$sgastat where name like 'ASH%';

POOL         NAME                               MB
------------ -------------------------- ----------
shared pool ASH buffers 2 SQL>

  直白的讲,V$ACTIVE_SESSION_HISTORY中能够记录多少会话信息,一方面取决于 该数据库的 SGA 分配给 ASHbuffers 的大小,另一方面取决于数据库的启动和关闭(重启数 据库时将重构 SGA 内存区)。这两方面的因素制约了 V$ACTIVE_SESSION_HISTORY中能够保存的会话信息的能力,做为DBA,我们肯定是希望 ASH 尽可能多的保留关于会话的信 息,但目前来看单纯依靠V$ACTIVE_SESSION_HISTORY肯定无法实现这点,那怎么办呢? 别担心,ORACLE又提供了 AWR特性,ASH 收集到的会话信息,是做为AWR中快照信息 的一部分,被保存到了硬盘上.

二.关于AWR

  • AWR 是 Oracle10g 版本推出的新特性,全称叫AutomaticWorkloadRepository-自动负载信息库
  • AWR 是通过对比两次快照(snapshot)收集到的统计信息,来生成报表数据,生成的报表包括多个部分
  • AWR 在生成报告时,可以选 择生成 TXT或 HTML两种格式的报告,相对来说,HTML更利于阅读

  生成分析报表种类:

  • awrrpt.sql:  生成指定快照区间的统计报表;
  • awrrpti.sql: 生成指定数据库实例(如:RAC中的某一个实例的awr),并且指定快照区间的统计报表;
  • awrsqlrpt.sql:生成指定快照区间,指定 SQL语句(实际指定的是该语句的SQLID) 的统计报表;
  • awrsqrpi.sql:生成指定数据库实例,指定快照区间的指定 SQL语句的统计报表;
  • awrddrpt.sql:指定两个不同的时间周期,生成这两个周期的统计对比报表;
  • awrddrpi.sql:指定数据库实例,并指定两个的不同时间周期,生成这两个周期的统 计对比报表

  提示:要想让 AWR 收集到准确的统计信息,从而生成可靠的 性能分析报告,必须将初始化参数STATISTICS_LEVEL的值设置为 TYPICAL或 ALL。

2.1生成标准统计报表

SQL> @$ORACLE_HOME/rdbms/admin/awrrpt.sql

Current Instance
~~~~~~~~~~~~~~~~ DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
864496616 RACDB 1 racdb1 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 --生成awr报告文件类型 Type Specified: html Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
864496616 2 RACDB racdb2 node2
* 864496616 1 RACDB racdb1 node1 Using 864496616 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: 7 --此处需指定要读取多少天内的快照信息! Listing the last 7 days of Completed Snapshots Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
racdb1 RACDB 1 21 Dec 2014 09:12 1 --快照的id 及生成时间
2 21 Dec 2014 10:00 1
3 21 Dec 2014 11:00 1
4 21 Dec 2014 12:00 1
5 21 Dec 2014 13:00 1
6 21 Dec 2014 14:00 1
7 21 Dec 2014 15:00 1
8 21 Dec 2014 16:00 1
9 21 Dec 2014 17:00 1
10 21 Dec 2014 18:00 1
11 21 Dec 2014 19:00 1 Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 6 --根据想要搜集信息的时间段,选择起始快照id

Begin Snapshot Id specified: 6 Enter value for end_snap: 10
End Snapshot Id specified: 10 Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_6_10.html. To use this name,
press <return> to continue, otherwise enter an alternative. Enter value for report_name: /home/oracle/awrrpt_1_6_10.html --生成awr报告文件名称 Using the report name /home/oracle/awrrpt_1_6_10.html

2.2 生成指定数据库实例的统计报表

  这项统计报表一般是针对多实例数据库,上面使用的脚本是生成数据库级别的统计报 表,对于多实例的数据库,有时候DBA 可能希望看到某个实例的表现,那么本脚本就能派 上用场了。

SQL> @$ORACLE_HOME/rdbms/admin/awrrpti.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'
Enter value for report_type: html Type Specified: html Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
864496616 2 RACDB racdb2 node2
* 864496616 1 RACDB racdb1 node1 Enter value for dbid: 864496616
Using 864496616 for database Id
Enter value for inst_num: 2
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: 7 Listing the last 7 days of Completed Snapshots Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
racdb2 RACDB 1 21 Dec 2014 09:11 1
2 21 Dec 2014 09:55 1
3 21 Dec 2014 10:51 1 11 21 Dec 2014 18:58 1 Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1
Begin Snapshot Id specified: 1 Enter value for end_snap: 3
End Snapshot Id specified: 3 Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_2_1_3.html. To use this name,
press <return> to continue, otherwise enter an alternative. Enter value for report_name: /home/oracle/awrrpt_2_1_3.html

2.3 生成不同时间段时的统计对比报表

  在AWR中, 直接就提供了对不同时间段时,数据库的性能统计做差异对比的功能

SQL> @$ORACLE_HOME/rdbms/admin/awrddrpt.sql

Current Instance
~~~~~~~~~~~~~~~~ DB Id DB Id DB Name Inst Num Inst Num Instance
----------- ----------- ------------ -------- -------- ------------
864496616 864496616 RACDB 1 1 racdb1 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
------------ -------- ------------ ------------ ------------
864496616 2 RACDB racdb2 node2
* 864496616 1 RACDB racdb1 node1 Database Id and Instance Number for the First Pair of Snapshots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using 864496616 for Database Id for the first pair of snapshots
Using 1 for Instance Number for the first pair of snapshots 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: 7 Listing the last 7 days of Completed Snapshots Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
racdb1 RACDB 1 21 Dec 2014 09:12 1
2 21 Dec 2014 10:00 1
3 21 Dec 2014 11:00 1
4 21 Dec 2014 12:00 1
5 21 Dec 2014 13:00 1
6 21 Dec 2014 14:00 1
7 21 Dec 2014 15:00 1
8 21 Dec 2014 16:00 1
9 21 Dec 2014 17:00 1
10 21 Dec 2014 18:00 1
11 21 Dec 2014 19:00 1 Specify the First Pair of Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 1

First Begin Snapshot Id specified: 1 Enter value for end_snap: 3
First End Snapshot Id specified: 3 Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
864496616 2 RACDB racdb2 node2
* 864496616 1 RACDB racdb1 node1 Database Id and Instance Number for the Second Pair of Snapshots
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Using 864496616 for Database Id for the second pair of snapshots
Using 1 for Instance Number for the second pair of snapshots 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_days2: 7 Listing the last 7 days of Completed Snapshots Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
racdb1 RACDB 1 21 Dec 2014 09:12 1
2 21 Dec 2014 10:00 1
3 21 Dec 2014 11:00 1
4 21 Dec 2014 12:00 1
5 21 Dec 2014 13:00 1
6 21 Dec 2014 14:00 1
7 21 Dec 2014 15:00 1
8 21 Dec 2014 16:00 1
9 21 Dec 2014 17:00 1
10 21 Dec 2014 18:00 1
11 21 Dec 2014 19:00 1 Specify the Second Pair of Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap2: 8

Second Begin Snapshot Id specified: 8 Enter value for end_snap2: 11
Second End Snapshot Id specified: 11 Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrdiff_1_1_1_8.html To use this name,
press <return> to continue, otherwise enter an alternative. Enter value for report_name: /home/oracle/awrdiff_1_1_1_8.html

三.几个相关概念---快照

3.1 Snapshots(快照)

  前面操作报表生成时,snap 这个关键字已经出现过黑多黑多次了,想必你对它充满了疑惑,这个东西是哪尬来的咋来的谁让它来的呢?事实上,Snap是 Snapshot的简写,这正是 AWR 在自动性方面的体现,虽然你没有创建,但是AWR自动帮你创建了(当然也可以手 动创建snapshot),并且是定时(每小时)创建,定期清除(保留最近 7 天)。 Snapshots 是一组某个时间点时历史数据的集合,这些数据就可被 ADDM(Automatic DatabaseDiagnosticMonitor)用来做性能对比。默认情况下,AWR 能够自动以每小时一次的 频率 生成 Snapshots 性能数据, 并保留 7 天,如果需要的话 ,DBA 可以通过 DBMS_WORKLOAD_REPOSITORY过程手动创建、删除或修改 snapshots。

3.2 手动创建Snapshots

  • 通过 DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT 过程,例如:
  • SQL>execdbms_workload_repository.create_snapshot();
  • 可以通过 DBA_HIST_SNAPSHOT 视图查看刚刚创建的 Snapshots信息。

3.3 手动删除Snapshots

  删除 Snapshots 是使用DBMS_WORKLOAD_REPOSITORY 包的另一个过程 : DROP_SNAPSHOT_RANGE,该过程在执行时可以通过指定 snap_id 的范围的方式一次删除多个 Snapshots,例如:

--查看删除前
SQL>select count(0) from dba_hist_snapshot where snap_id between 7509 and 7518; --删除
SQL>begin
2 dbms_workload_repository.drop_snapshot_range(
3 low_snap_id=>7509,
4 high_snap_id=>7518,
5 dbid=>3812548755);
6 end;
7 / --查看删除后
SQL>select count(0) from dba_hist_snapshot where snap_id between 7509 and 7518; --当snapshots 被删除的话,与其关联的ASH 记录也会级联删除。

3.4 修改Snapshots

  DBA 可以调整包括快照收集频率、快照保存时间、以及捕获的SQL数量三个方面的设置.分别对应 MODIFY_SNAPSHOT_SETTINGS的三个参数:

  • Retention:设置快照保存的时间,单位是分钟。可设置的值最小为1 天,最大为100 年。设置该参数值为0 的话,就表示永久保留收集的快照信息。
  • Interval:设置快照收集的频率,以分钟为单位。可设置的值最小为10 分钟,最大 为 1 年。如果设置该参数值为0,就表示禁用 AWR特性。
  • Topnsql:指定收集的比较占用资源的SQL数量,可设置的值最小为30,最大不超 过 100000000。

  通过 DBA_HIST_WR_CONTROL 视图查看当前快照收集的相关设置:

SQL> select*from dba_hist_wr_control;

四.几个相关概念---基线

4.1 Baselines(基线)

  Baseline,直译的话叫做基线,顾名思义的方式理解,就是用于比较的基本线。因为 Baseline 中包含指定时间点时的性能数据,因此就可以用来与其它时间点时的状态数据做对比,以分析性能问题。

  创建 Baseline 时,Snapshots是做为其中的一个组成部分存在,因此一般来说当 AWR 自动维护快照时,如果定义过 baseline,与 baseline 相关的快照不会被删除,即使是过期的快照,这样就相当于手动保留了一份统计数据的历史信息,DBA 可以在适当的时间将其与 现有的快照进行对比,以生成相关的统计报表。

4.2 创建Baseline

  用户可以通过 DBMS_WORKLOAD_REPOSITORY包中的相关过程,手动的创建或删除 Baseline。

    创建 Baseline 使用CREATE_BASELINE过程,执行该过程时分别指定开始和结果的snap_id,然后为该 baseline 定义一个名称即可,例如: 

SQL>BEGIN
2 DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(start_snap_id => 7550,
3 end_snap_id =>7660,
4 baseline_name=>'am_baseline');
5 END;
6 /

--查看
   SQL>select dbid,baseline_name,start_snap_id,end_snap_id from dba_hist_baseline;

4.3 删除Baseline

  删除 Baseline 使用 DROP_BASELINE 过程,删除时可以通过 cascade 参数选择是否将其关联的 Snapshots 级别进行删除,例如: 

SQL>BEGIN
2 DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE(baseline_name => 'am_baseline',
3 cascade =>true);
4 END;
5 / SQL>select * from dba_hist_baseline; SQL>select * from dba_hist_snapshot where snap_id between 7550 and 7660;

  如上例中所示,删除时指定了cascade 参数值为 true,对应的 snap也被级联删除了。

----整理自君三四笔记

ORACLE AWR 和 ASH的更多相关文章

  1. ORACLE AWR结合ASH诊断分析enq: TX - row lock contention

    公司用户反馈一系统在14:00~15:00(2016-08-16)这个时间段反应比较慢,于是生成了这个时间段的AWR报告, 如上所示,通过Elapsed Time和DB Time对比分析,可以看出在这 ...

  2. [转]oracle awr报告生成和分析

    转自:http://blog.csdn.net/cuker919/article/details/8767328 最近由于数据库cpu占用非常高,导致VCS常常自动切换,引起很多问题. 最近学习一下数 ...

  3. Oracle性能调整ASH,AWR,ADDM

    ASH (Active Session History)ASH以V$SESSION为基础,每秒采样一次,记录活动会话等待的事件.不活动的会话不会采样,采样工作由新引入的后台进程MMNL来完成.ASH ...

  4. 如何评估oracle AWR 的在oracle 中的存储情况

    如何评估oracle AWR 的在oracle 中的存储情况 如果把awr保存时间从默认的7天修改为30天,采样时间从1小时修改到更短,修改之后如何预估空间占用? ------------------ ...

  5. Oracle AWR报告生成和性能分析

    目录 一.AWE报告生成步骤 1.1 工具选择 1.2 自动创建快照 1.3 手工创建快照 1.4 生成AWR报告 二.AWR报告分析 2.1 AWR之DB Time 2.2 AWR之load_pro ...

  6. 【转】ORACLE AWR报告

    转自:http://blog.csdn.net/liqfyiyi/article/details/8236864 About Oracle AWR Oracle AWR is a powerful m ...

  7. 快速熟悉 Oracle AWR 报告解读

    目录 AWR报告简介 AWR报告结构 基本信息 Report Summary Main Report RAC statistics Wait Event Statistics 参考资料 本文面向没有太 ...

  8. Oracle AWR 数据导入/导出的步骤

    LINUX状态下,连接oracle用户:su - oracle  1.上传采集快照.dmp文件至服务器  (dbid:4292035712)  919219826 2.在服务器端创建目录 (即文件夹a ...

  9. 媲美oracle awr/statspack的mysql awr第一版发布

    现发布alpha版mysql awr,其提供的特性类似于oracle awr或statspack+集中式监控.对于原来从事oracle dba或者相关运维的人原来说,这会是个不错的选择. 至于我为什么 ...

随机推荐

  1. [Javascript] 面向对象编程思想

    1.创建对象 1.1 new 用new进行创建对象: var user = new Object(); user.age = 12;//同时为对象添加属性 user.name = 'ajun'; 1. ...

  2. jQery无缝滚动效果

    思路: 赋值所有li,添加到ul末尾,重新计算ul宽度 每次移动一个固定的值,当超出一半时,将ul拉回原位 以下代码 <!DOCTYPE html> <html> <he ...

  3. JD轮播图代码

    <!DOCTYPE html>   <html>   <head>   <title>jd网站的轮播图效果</title>   <me ...

  4. java 解析XML文档

    Java 解析XML文档 一.解析XML文档方式: 1.DOM方式:将整个XML文档读取到内存中,按照XML文件的树状结构图进行解析. 2.SAX方式:基于事件的解析,只需要加载XML中的部分数据,优 ...

  5. 怒刷DP之 HDU 1260

    Tickets Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  6. hdu 4403 简单搜索

    思路:分等号左边和右边进行搜索 #include<iostream> #include<cstdio> #include<cstring> #include< ...

  7. orcale 列改为大字段

    --添加临时列ALTER TABLE MPD_TASK_LIST ADD(  CLOB_TEMP clob);--数据拷贝到临时列update MPD_TASK_LIST set CLOB_TEMP ...

  8. 从模态视图push到另一个视图

    //需要给模态视图创建一个Nav,然后再调用presentViewController if (_loginVC == nil) { _loginVC = [[LoginViewController ...

  9. asp.net MVC dropList 绑定

    废话我就不多说了..上个图.给自己备忘一下

  10. PHP计算中英混输字符串长度

    最近做项目中碰到需要post value length check的这么一个情况 有这么一个需求, 需要backend来处理post过来的中英混输的数据. 对其限制的规则是中文10个字符, 英文20个 ...