Oracle ASH报告生成和性能分析

我写的SQL调优专栏:https://blog.csdn.net/u014427391/article/category/8679315

对于局部的,比如某个页面列表sql,我们可以使用Oracle的执行计划进行sql调优,但是对于整个系统来说,你可以知道哪些sql比较耗时?当然可以通过查Oracle的共享池得到,不过Oracle系统本身就提供了几种性能分析报告,比如AWR、ASH、ADDM等等报告,本博客介绍一下ASH性能分析报告

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

v$active_session_history视图提供了在实例级别抽取会话活动信息。活动会话每分钟会被抽样一次且被存储在sga中的循环缓冲区中。任何被连接到数据库且正等待一个不属于空闲等待时间的会话会被考虑是一个活动的会话。每个会话抽样都是一组行数据且通过v$active_session_history视图来返回每个被抽样活动会话的行数据,返回最新被抽样会话的第一行数据。

一、ASH报告生成

继上一篇AWR方面的博客之后,https://smilenicky.blog.csdn.net/article/details/89414432,我再写一篇ASH方面的博客:

1.1 工具选择

对于Oracle数据库可以使用sqlplus或者plsql developer客户端软件
sqlplus 使用
可以使用sqlplus工具登录
进入数据库

sqlplus / as sysdba

查看用户

show parameter db_name

用登录之后才可以使用
plsql developer使用
plsql developer也可以使用,登录之后,选择文件(File)->新建(New)->命令窗口(Command Window)

在这里插入图片描述

1.2 自动创建快照

开始压测后执行

exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();

可以通过dba_hist_wr_control查看当前的配置情况,当前awr为每1小时做一次数据快照,保留时间为8天。

 select * from dba_hist_wr_control;
在这里插入图片描述

修改配置,每隔30分钟收集一次,保存1天

execute dbms_workload_repository.modify_snapshot_settings(interval=>30,retention=>14000);

关闭自动收集

SQL>exec dbms_workload_repository.modify_snapshot_settings (interval=>0,retention=>24*60);

1.3 手工创建快照

除了自动创建快照,也可以手工创建快照

select dbms_workload_repository.create_snapshot() from dual;

1.4 ASH报告生成

对于sqlplus客户端的可以使用

@?/rdbms/admin/ashrpt.sql

对于plsql客户端,我用绝对路径去执行,@?的命令找不到文件
这个要根据自己的Oracle安装路径去修改,例如:

    @D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/ashrpt.sql

(1)日志报告类型

Enter value for report_type: text

选择生成的ASH 报告类型,是text 还是html,一般选择html

(2)日志报告起始时间

Enter value for begin_time: 04/18/1920:00:00

输入ASH 开始的时间,时间格式上面的示例有说明,比如我这里是2019年4月18日晚上20:00:00开始。

(3)日志报告结束时间

Enter value for duration:15

输入ASH 结束时间,默认是SYSDATE - begin_time,一般输入,一般默认是秒或者分组,拿出15分组的ash分析日志来。

(4) ASH报告名称
Enter value of report name:ash20190420
输入ASH报告名称,可以随意填,非生产,报告名称,打印的日志后面可以找到报告存放路径,比如:

D:\oracle\product\11.2.0\dbhome_1\RDBMS\ADMIN\ash.html

SQL> @D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/ashrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
      DBID DB_NAME      INST_ INST_NAME
---------- ------------ ----- ------------
1525762377 ORCL             1 orcl
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Type Specified:  html
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DBBID        INSTT DBB_NAME     INSTT_NAME   HOST
------------ ----- ------------ ------------ ------------
* 1525762377     1 ORCL         orcl         PC-201508171
                                             906
Defaults to current database
Using database id: 1525762377                                
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                                        
PL/SQL procedure successfully completed
...
0
PL/SQL procedure successfully completed
...
18-Apr-19 22:05:54
ASH Samples in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Oldest ASH sample available:  09-Apr-19 22:00:36   [    12968 mins in the past] Latest ASH sample available:  18-Apr-19 22:05:54   [        3 mins in the past]
...
18-Apr-19 22:05:54
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
Report begin time specified: 04/18/1920:00:00
PL/SQL procedure successfully completed

18-Apr-20 00:00:00
Enter duration in minutes starting from begin time:
Defaults to SYSDATE - begin_time
Press Enter to analyze till current time
Report duration specified:   7200
PL/SQL procedure successfully completed
...
23-Apr-20 00:00:00
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_0423_0000.html.  To use this name,
press <return> to continue, otherwise enter an alternative.
Using the report name ash.html
Summary of All User Input -------------------------                                                        Format         : HTML                                                            DB Id          : 1525762377                                                      Inst num       : 1                                                               Begin time     : 18-Apr-20 00:00:00                                              End time       : 23-Apr-20 00:00:00                                              Slot width     : Default                                                         Report targets : 0                                                               Report name    : ash.html
...
23-Apr-20 00:00:00
Started spooling to D:\oracle\product\11.2.0\dbhome_1\RDBMS\ADMIN\ash.html

二、ASH报告指标分析

ASH报告就非常直接了,直接给出等待事件和哪些SQL关联,然后我们就可以拿SQL去调优了

图来自《收获,不止SQL优化》一书


在这里插入图片描述
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容