一.关于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. FVDI Commander products be replaced SVDI tools,really?

    You may have heard that some FVDI Commander products are being replaced by the new SVDI tools. This ...

  2. Android(java)学习笔记264:Android下的属性动画高级用法(Property Animation)

    1. 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是最常用的一些用法,这些用法足以覆盖我们平时大多情况下的动画需求了.但是,正如上篇文章当中所说到的,属性动画对补间动画 ...

  3. 关于如何用sql语句查询出连续的一串数字

    在数据库操作中,经常有一些这样的操作:插入诺干条测试数据.查询这个月的登录情况(没有登录的日期不能不存在,要显示数量为0),获取诺干条guid. 这些的基础都是怎么生成连续的一串数字  1 2  3  ...

  4. How To Install Development Tools In Linux

      In this brief tutorial, we will be discussing how to install development tools in popular Linux di ...

  5. Android Bitmap详细介绍(转)

    转自: Bitmap详细介绍 package com.testbitmapscale; import java.io.File; import java.io.FileInputStream; imp ...

  6. HTML5+开发移动app-mui开发示例

    mui 官网:http://dcloudio.github.io/mui/ 说明:希望你可以把官网内容通读一遍,这是以后开发的基础 开始 新建项目 在首页点击新建移动App,如下: 或者在项目管理器内 ...

  7. MongoDB - The mongo Shell, Configure the mongo Shell

    Customize the Prompt You may modify the content of the prompt by setting the variable prompt in the  ...

  8. 二维码zxing源码分析(一)camera部分

    首先,我们先把zxing的源代码给下载下来,这个网上有很多,我下载的是2.3的,不得不说这个谷歌提供的包包含的功能还是很全面的.     我把下载的包解压后,找到android文件夹,导入到ecpli ...

  9. 十一、Android学习笔记_AsyncQueryHandler的应用

    研究AsyncQueryHandler这个类的时候遇到了几个重要的不清楚的知识点 1. Handler与Thread,Looper的关系 2. HandlerThread是干什么用的 3. Threa ...

  10. 正确理解SQL Server的许可证(转)

    今天在论坛上看到有人讨论如果使用SQL Server作为SEPM的后台数据库,需要多少个CAL的问题:   If I do have to use SQL Server what type of li ...