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

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