ASH (Active Session History)活跃会话历史信息

一、ASH架构图

这里写图片描述

二、ASH原理

  在Oracle数据库中,实时捕获相关性能数据是通过ASH工具来实现的。ASH以V$SESSION为基础,每秒采样一次,记录活跃会话等待的事件。ASH直接读取Oracle使用的特定结构数据,而不是使用SQL,因此该方式比较高效。不活跃的会话不会采样,采样工作由后台进程MMNL来完成。
  v$active_session_history视图提供了在实例级别抽取的活跃会话信息。通过该视图提供的最详细最完整性能数据,可作为定位性能故障的证据。任何被连接到数据库且正等待一个不属于空闲等待事件的会话会被考虑是一个活跃的会话。每个会话抽样都是一组行数据且通过v$active_session_history视图来返回每个被抽样活跃会话的行数据,返回最新被抽样会话的第一行数据。数据字典dba_hist_active_sess_history是视图v$active_session_history的历史数据,dba_hist_active_sess_history视图默认每十秒收集一次信息储存在磁盘中。也就是说最终保存到磁盘的数据也就是实时收集数量量的1/10。相应地,可用于诊断性能的数据也就没有v$active_session_history更详细,更丰富。
   活跃会话每分钟会被抽样一次且被存储在sga中的循环缓冲区中,随着系统活跃的增加,可以存储在循环缓冲区中的会话活跃的秒数将减少。会话样本的时间保留在vv视图中,在v视图中显示的会话活跃的秒数是完全依赖于数据库活跃的。ASH buffers 的最小值为1MB,最大值不超过30MB,内存中记录数据。期望值是记录一小时的内容,所以ASH 内存记录数据始终是有限的。
   ASH被设计为内存中的滚动缓冲区,以前的信息在需要时被覆盖。由于ASH缓冲区中的数据量可能非常大,并且将其全部刷新到磁盘是不可接受的。更有效的方法是过滤历史数据,同时将其刷新到工作负载存储库。每隔60分钟通过可管理性监视器(MMON)进程自动执行此操作,并且每当缓冲区已满时,都通过MMNL进程完成。
注意:ASH的存储器来自系统全局区域(SGA),它在实例的使用寿命期间是固定的。它代表每个CPU 2 MB的内存。 ASH不能超过SGA_TARGET的百分之五。
一般在线上实时诊断数据库性能问题,特别是资源突然打高场景,这个时候用ash实时出日志报告,就能很大程度上准确定位问题所在。
在这里插入图片描述

活跃会话数据流:
   v$session(ASH Buffer) —>v$active_session_history—>dba_hist_active_sess_history(AWR仓库)
生成ASH报告:
SQLPLUS>@?/rdbms/admin/ashrpt.sql
sys@orcl(10)>  select pool, name, bytes/1024/1024 From v$sgastat where name like '%ASH %';

POOL                     NAME                                                 BYTES/1024/1024
------------------------ ---------------------------------------------------- ---------------
shared pool              ASH buffers                                                        8

Elapsed: 00:00:00.01
//相关视图
v$session (当前正在发生)
v$session_wait (当前正在发生)
v$session_wait_history (会话最近的10次等待事件)
v$active_session_history (内存中的ASH采集信息,理论为1小时)
wrh$_active_session_history (写入AWR库中的ASH信息,理论为1小时以上)
dba_hist_active_sess_history (根据wrh$_active_session_history生成的视图)

三、ASH报告解读

sys@orcl(10)> @?/rdbms/admin/ashrpt.sql

Current Instance
~~~~~~~~~~~~~~~~

   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 1553656570 ORCL                1 orcl

Elapsed: 00:00:00.00

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: html  --指定报告类型,此处使用html

Type Specified:                  html

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
* 1553656570        1 ORCL         orcl         oracle

Defaults to current database

Using database id:
1553656570

Enter instance numbers. Enter 'ALL' for all instances in a
RAC cluster or explicitly specify list of instances (e.g., 1,2,3).
Defaults to current instance.

Using instance number(s): --输入实例号,RAC可以选择ALL或者特定实例号
1 

ASH Samples in this Workload Repository schema --当前已保存的ASH sample数据
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oldest ASH sample available:                               23-May-20 17:35:09
[   51659 mins in the past]
Latest ASH sample available:                               28-Jun-20 14:33:56
[       0 mins in the past]


Specify the timeframe to generate the ASH report
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter begin time for report: --输入起止时间

--    Valid input formats:
--      To specify absolute begin time:
--        [MM/DD[/YY]] HH24:MI[:SS]
--        Examples: 02/23/03 14:30:15
--                  02/23 14:30:15
--                  14:30:15
--                  14:30
--      To specify relative begin time: (start with '-' sign)
--        -[HH24:]MI
--        Examples: -1:15  (SYSDATE - 1 Hr 15 Mins)
--                  -25    (SYSDATE - 25 Mins)

Defaults to -15 mins 默认为-15分钟
Enter value for begin_time: 默认为当前时间
Report begin time specified:

Enter duration in minutes starting from begin time:
Defaults to SYSDATE - begin_time
Press Enter to analyze till current time
Enter value for duration:
Report duration specified:

Using 28-Jun-20 14:19:42 as report begin time
Using 28-Jun-20 14:34:47 as report end time

以下部分描述如何生成特定的ASH报告:
Specify Slot Width (using ashrpti.sql) for 'Activity Over Time' section
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- Explanation:
--   In the 'Activity Over Time' section of the ASH report,
--   the analysis period is divided into smaller slots
--   and top wait events are reported in each of those slots.

-- Default:
--   The analysis period will be automatically split upto 10 slots
--   complying to a minimum slot width of
--     1 minute,  if the source is V$ACTIVE_SESSION_HISTORY or
--     5 minutes, if the source is DBA_HIST_ACTIVE_SESS_HISTORY.


Specify Slot Width in seconds to use in the 'Activity Over Time' section:
Defaults to a value as explained above:
Slot Width specified:


Specify Report Targets (using ashrpti.sql) to generate the ASH report
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- Explanation:
--   ASH Report can accept "Report Targets",
--   like a particular SQL statement, or a particular SESSION,
--   to generate the report on. If one or more report targets are
--   specified, then the data used to generate the report will only be
--   the ASH samples that pertain to ALL the specified report targets.

-- Default:
--   If none of the report targets are specified,
--   then the target defaults to all activity in the database instance.


Specify SESSION_ID (eg: from V$SESSION.SID) report target:
Defaults to NULL:
SESSION report target specified:


Specify SQL_ID (eg: from V$SQL.SQL_ID) report target:
Defaults to NULL: (% and _ wildcards allowed)
SQL report target specified:


Specify WAIT_CLASS name (eg: from V$EVENT_NAME.WAIT_CLASS) report target:
[Enter 'CPU' to investigate CPU usage]
Defaults to NULL: (% and _ wildcards allowed)
WAIT_CLASS report target specified:


Specify SERVICE_HASH (eg: from V$ACTIVE_SERVICES.NAME_HASH) report target:
Defaults to NULL:
SERVICE report target specified:


Specify MODULE name (eg: from V$SESSION.MODULE) report target:
Defaults to NULL: (% and _ wildcards allowed)
MODULE report target specified:


Specify ACTION name (eg: from V$SESSION.ACTION) report target:
Defaults to NULL: (% and _ wildcards allowed)
ACTION report target specified:


Specify CLIENT_ID (eg: from V$SESSION.CLIENT_IDENTIFIER) report target:
Defaults to NULL: (% and _ wildcards allowed)
CLIENT_ID report target specified:


Specify PLSQL_ENTRY name (eg: "SYS.DBMS_LOB.*") report target:
Defaults to NULL: (% and _ wildcards allowed)
PLSQL_ENTRY report target specified:

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is ashrpt_1_0628_1434.html.  To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: ash.html

Using the report name                      ash.html

Summary of All User Input
-------------------------
Format         : HTML
DB Id          : 1553656570
Inst num       : 1
Begin time     : 28-Jun-20 14:19:42
End time       : 28-Jun-20 14:34:47
Slot width     : Default
Report targets : 0
Report name    : ash.html

头部信息
在这里插入图片描述
头部信息包含实例基本信息、内存相关基本信息、采样基本信息。
ASH报告目录

Top Event
Load Profile
Top SQL
Top PL/SQL
Top Java
Top Call Types
Top Sessions
Top Objects/Files/Latches
Active  Over Time

在这里插入图片描述
Top Event
在这里插入图片描述
Top Event代表被抽样会话活动中由用户,后台等产生的主要等待事件,主要等待事件,意味着采样期间这些事件是产生性能问题的根源。
Top Event包含以下部分:
(1)Top User Events首要用户事件
主要用户事件,也称为前台等待事件,信息显示了在抽样会话活动中占很高百分比的用户进程等待事件。

(2)Top Background Events首要后台事件
这部分信息显示了在抽样会话活动中占很高百分比的后台进程等待事件。

(3)Top Event P1/P2/P3 Values首要等待事件参数P1/P2/P3
这部分信息显示了在抽样会话活动中占很高百分比的等待事件的参数值它通过总的等待时间(%Event)百分比进行排序后被显示.对于每一个等待事件p1,p2,p3的值与等待事件参数parameter 1,parameter 2,parameter 3这三个列相关联,分别是文件号,块号,set-id#
Load Profie
在这里插入图片描述
Load Profie包含占很高百分比的服务和模块信息、客户端标识符、sql命令类型。
Top SQL
在这里插入图片描述
TOP SQL列出了与top event相关的SQL、行扫描top SQL、一些未绑定变量的sql以及详细的SQL列表。
Top PL/SQL
在这里插入图片描述
Top PL/SQL代表主要耗时的存储过程。
Top Java
在这里插入图片描述
Top Java代表主要耗时的java
Top Call Types
在这里插入图片描述
Top Call Types代表主要的调用。
Top Sessions
在这里插入图片描述
Top Sessions列出了活动最频繁的会话信息、被阻塞的会话信息以及占很高百分比的正处于等待的并行查询。
Top Objects/Files/Latches
在这里插入图片描述
Top Objects/Files/Latches代表占访问量很高百分比的数据库文件、对象、闩锁信息。
Active Over Time
在这里插入图片描述
Active Over Time代表按不同时间片段来展现活动等待事件。
slot time(持续时间) 时段的持续时间
solt count 在时段中抽样会话的数量
event 在时段中顶级的三个等待事件
event count ash抽样等待的等待事件的数量
%event ash抽样等待的等待事件在整个分析期间所占的百分比

本文参考:https://blog.csdn.net/leshami/article/details/73526881

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章