1 、 ASH ( Active SessionHistory )
ASH 以 V$SESSION 为基础,每秒采样一次,记录活动会话等待的事件。不活动的会话不会采样,采样工作由新引入的后台进程 MMNL 来完成。
v$active_session_history 视图提供了在实例级别抽取会话活动信息。活动会话每分钟会被抽样一次且被存储在 sga 中的循环缓冲区中 . 任何被连接到数据库且正等待一个不属于空闲等待事件的会话会被考虑是一个活动的会话。每个会话抽样都是一组行数据且通过 v$active_session_history 视图来返回每个被抽样活动会话的行数据,返回最新被抽样会话的第一行数据。因为活动会话抽样是存储在 sga 中的循环缓冲区中,系统活动越大的,活动时间越少会话的可以被存储在循环缓冲区中。这意味着在这期间被抽样的每个会话会出现在 v$ 视图中或者会话活动的时间会在 v$ 视图中被显示,这完全依赖于数据库活动情况。
ASH buffers 的最小值为 1MB ,最大值不超过 30MB. 内存中记录数据。期望值是记录一小时的内容,所以说 ASH 内存记录数据始终是有限的
一般在线上实时诊断数据库性能问题,特别是负载高 w 出来上了 100 后, cpu 100% ,这个时候用 ash 实时出日志报告,就能很大程度上准确定位问题所在。
2 、 ASH 的主要要素点
在执行 SQL> @?/rdbms/admin/ashrpt.sql 命令后,会让有如下参数需要手动填写:
日志报告类型
Enter value for report_type: text -- 选择生成的 ASH 报告类型,是 text 还是 html
( 2 )日志报告起始时间
Enter value for begin_time: 08/31/16 20:00:00
-- 输入 ASH 开始的时间,时间格式上面的示例有说明,比如我这里是 2016 年 8 月 31 日晚上 20:00:00 开始。
( 3 )日志报告结束时间
Enter value for duration: 120( 此处是用分钟来计算了,是从开始的时间往后 2 个小时 )
-- 输入 ASH 结束时间,默认是 SYSDATE - begin_time ,一般输入的分析统计的总时间,一般默认是 分钟 ,拿出 2 个小时的 ash 分析日志来。
( 4 )报告文件名
Enter value for report_name: /home/oracle/ ceshi. html
-- 输入 ASH 报告的名称,可以指定生成的目录,默认情况是当前登陆 sqlplus 的目录。 这里的扩展最好加上,如果不加扩展名,扩展名会变成 lst. 不影响数据,但是会影响阅读效率。
3 、 ASH 操作实战记录
SYS@sjptdb1>@?/rdbms/admin/ashrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
3581456119 SJPTDB 1 sjptdb1
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
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
------------ -------- ------------ ------------ ------------
3581456119 2 SJPTDB sjptdb2 xf01dbadm02.
hlic.cn
* 3581456119 1 SJPTDB sjptdb1 xf01dbadm01.
hlic.cn
Defaults to current database
Using database id: 3581456119
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): 1
ASH Samples in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oldest ASH sample available: 25-Nov-18 23:00:21 [ 13686 mins in the past]
Latest ASH sample available: 05-Dec-18 11:06:27 [ 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
Enter value for begin_time: 05/12 8:00
Report begin time specified: 05/12 8:00
Enter duration in minutes starting from begin time:
Defaults to SYSDATE - begin_time
Press Enter to analyze till current time
Enter value for duration: 7200
Report duration specified: 7200
Using 12-May-18 08:00:00 as report begin time
Using 17-May-18 08:00:00 as report end time
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:
........( 此处省略 )
End of Report