我写的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工具登录

进入数据库

  1. sqlplus / as sysdba

查看用户

  1. show parameter db_name

用登录之后才可以使用

plsql developer使用

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

1.2 自动创建快照

开始压测后执行

  1. exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();

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

  1. select * from dba_hist_wr_control;



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

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

关闭自动收集

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

1.3 手工创建快照

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

  1. select dbms_workload_repository.create_snapshot() from dual;

1.4 ASH报告生成

对于sqlplus客户端的可以使用

  1. @?/rdbms/admin/ashrpt.sql

对于plsql客户端,我用绝对路径去执行,@?的命令找不到文件

这个要根据自己的Oracle安装路径去修改,例如:

  1. @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

  1. SQL> @D:/oracle/product/11.1.0/db_1/RDBMS/ADMIN/ashrpt.sql
  2. Current Instance
  3. ~~~~~~~~~~~~~~~~
  4. DBID DB_NAME INST_ INST_NAME
  5. ---------- ------------ ----- ------------
  6. 1525762377 ORCL 1 orcl
  7. Specify the Report Type
  8. ~~~~~~~~~~~~~~~~~~~~~~~
  9. Enter 'html' for an HTML report, or 'text' for plain text
  10. Defaults to 'html'
  11. Type Specified: html
  12. Instances in this Workload Repository schema
  13. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. DBBID INSTT DBB_NAME INSTT_NAME HOST
  15. ------------ ----- ------------ ------------ ------------
  16. * 1525762377 1 ORCL orcl PC-201508171
  17. 906
  18. Defaults to current database
  19. Using database id: 1525762377
  20. Enter instance numbers. Enter 'ALL' for all instances in a
  21. RAC cluster or explicitly specify list of instances (e.g., 1,2,3).
  22. Defaults to current instance.
  23. Using instance number(s): 1
  24. PL/SQL procedure successfully completed
  25. ...
  26. 0
  27. PL/SQL procedure successfully completed
  28. ...
  29. 18-Apr-19 22:05:54
  30. ASH Samples in this Workload Repository schema
  31. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. 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]
  33. ...
  34. 18-Apr-19 22:05:54
  35. Specify the timeframe to generate the ASH report
  36. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. Enter begin time for report:
  38. -- Valid input formats:
  39. -- To specify absolute begin time:
  40. -- [MM/DD[/YY]] HH24:MI[:SS]
  41. -- Examples: 02/23/03 14:30:15
  42. -- 02/23 14:30:15
  43. -- 14:30:15
  44. -- 14:30
  45. -- To specify relative begin time: (start with '-' sign)
  46. -- -[HH24:]MI
  47. -- Examples: -1:15 (SYSDATE - 1 Hr 15 Mins)
  48. -- -25 (SYSDATE - 25 Mins)
  49. Defaults to -15 mins
  50. Report begin time specified: 04/18/1920:00:00
  51. PL/SQL procedure successfully completed
  52. 18-Apr-20 00:00:00
  53. Enter duration in minutes starting from begin time:
  54. Defaults to SYSDATE - begin_time
  55. Press Enter to analyze till current time
  56. Report duration specified: 7200
  57. PL/SQL procedure successfully completed
  58. ...
  59. 23-Apr-20 00:00:00
  60. Specify Slot Width (using ashrpti.sql) for 'Activity Over Time' section
  61. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. -- Explanation:
  63. -- In the 'Activity Over Time' section of the ASH report,
  64. -- the analysis period is divided into smaller slots
  65. -- and top wait events are reported in each of those slots.
  66. -- Default:
  67. -- The analysis period will be automatically split upto 10 slots
  68. -- complying to a minimum slot width of
  69. -- 1 minute, if the source is V$ACTIVE_SESSION_HISTORY or
  70. -- 5 minutes, if the source is DBA_HIST_ACTIVE_SESS_HISTORY.
  71. Specify Slot Width in seconds to use in the 'Activity Over Time' section:
  72. Defaults to a value as explained above:
  73. Slot Width specified:
  74. Specify Report Targets (using ashrpti.sql) to generate the ASH report
  75. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. -- Explanation:
  77. -- ASH Report can accept "Report Targets",
  78. -- like a particular SQL statement, or a particular SESSION,
  79. -- to generate the report on. If one or more report targets are
  80. -- specified, then the data used to generate the report will only be
  81. -- the ASH samples that pertain to ALL the specified report targets.
  82. -- Default:
  83. -- If none of the report targets are specified,
  84. -- then the target defaults to all activity in the database instance.
  85. Specify SESSION_ID (eg: from V$SESSION.SID) report target:
  86. Defaults to NULL:
  87. SESSION report target specified:
  88. Specify SQL_ID (eg: from V$SQL.SQL_ID) report target:
  89. Defaults to NULL: (% and _ wildcards allowed)
  90. SQL report target specified:
  91. Specify WAIT_CLASS name (eg: from V$EVENT_NAME.WAIT_CLASS) report target:
  92. [Enter 'CPU' to investigate CPU usage]
  93. Defaults to NULL: (% and _ wildcards allowed)
  94. WAIT_CLASS report target specified:
  95. Specify SERVICE_HASH (eg: from V$ACTIVE_SERVICES.NAME_HASH) report target:
  96. Defaults to NULL:
  97. SERVICE report target specified:
  98. Specify MODULE name (eg: from V$SESSION.MODULE) report target:
  99. Defaults to NULL: (% and _ wildcards allowed)
  100. MODULE report target specified:
  101. Specify ACTION name (eg: from V$SESSION.ACTION) report target:
  102. Defaults to NULL: (% and _ wildcards allowed)
  103. ACTION report target specified:
  104. Specify CLIENT_ID (eg: from V$SESSION.CLIENT_IDENTIFIER) report target:
  105. Defaults to NULL: (% and _ wildcards allowed)
  106. CLIENT_ID report target specified:
  107. Specify PLSQL_ENTRY name (eg: "SYS.DBMS_LOB.*") report target:
  108. Defaults to NULL: (% and _ wildcards allowed)
  109. PLSQL_ENTRY report target specified:
  110. Specify the Report Name
  111. ~~~~~~~~~~~~~~~~~~~~~~~
  112. The default report file name is ashrpt_1_0423_0000.html. To use this name,
  113. press <return> to continue, otherwise enter an alternative.
  114. Using the report name ash.html
  115. 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
  116. ...
  117. 23-Apr-20 00:00:00
  118. Started spooling to D:\oracle\product\11.2.0\dbhome_1\RDBMS\ADMIN\ash.html

二、ASH报告指标分析

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

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

Oracle ASH报告生成和性能分析的更多相关文章

  1. Oracle AWRDD报告生成和性能分析

    我写的SQL调优专栏:https://blog.csdn.net/u014427391/article/category/8679315 对于局部的,比如某个页面列表sql,我们可以使用Oracle的 ...

  2. Oracle ADDM报告生成和性能分析

    我写的SQL调优专栏:https://blog.csdn.net/u014427391/article/category/8679315 对于局部的,比如某个页面列表sql,我们可以使用Oracle的 ...

  3. Oracle AWRSQRPT报告生成和性能分析

    我写的SQL调优专栏:https://blog.csdn.net/u014427391/article/category/8679315 对于局部的,比如某个页面列表sql,我们可以使用Oracle的 ...

  4. Oracle AWR报告生成和性能分析

    目录 一.AWE报告生成步骤 1.1 工具选择 1.2 自动创建快照 1.3 手工创建快照 1.4 生成AWR报告 二.AWR报告分析 2.1 AWR之DB Time 2.2 AWR之load_pro ...

  5. ORACLE AWR报告生成步骤

    ORACLE AWR报告生成步骤 (以PL/SQL中命令窗口为例) 1.sqlplus或plsql的commod窗口(命令窗口)运行命令 @D:\oracle\product\10.2.0\db_1\ ...

  6. Oracle Update 语句语法与性能分析 - 多表关联

    Oracle Update 语句语法与性能分析 - 多表关联   为了方便起见,建立了以下简单模型,和构造了部分测试数据: 在某个业务受理子系统BSS中, SQL 代码 --客户资料表 create ...

  7. [转]oracle awr报告生成和分析

    转自:http://blog.csdn.net/cuker919/article/details/8767328 最近由于数据库cpu占用非常高,导致VCS常常自动切换,引起很多问题. 最近学习一下数 ...

  8. oracle sql语句跟踪及性能分析工具实现

    在网上找了一大圈,没找着合适的工具来跟踪oracle一段时间的sql. 我们的场景是打算自动化跑遍所有场景(rft)+fiddler跟踪请求+后端跟踪sql,根据结果去分析慢的请求和sql,本来awr ...

  9. Oracle awr报告生成操作步骤

    1.登录主机切换到oracle用户 ssh root@192.168.220.128 su - oracle 2.以sysdba身份登录数据库 sqlplus / as sysdba 3.执行@?/r ...

随机推荐

  1. jquery-bootgrid

    http://www.jquery-bootgrid.com/GettingStarted 日志是生产环境非常重要的配置,在迁移老的工程到spring-boot时日志的设置兼容很重要,以下是自己在配置 ...

  2. FPGA学习笔记(二)——FPGA学习路线及开发流程

    ###### [该随笔部分内容转载自小梅哥]       ######### 一.FPGA学习路线 工具使用 -> 语法学习 -> 逻辑设计 -> IP使用 ->接口设计 -& ...

  3. javascript 判断对象类型

    typeof typeof是一个一元运算符,它返回的结果 始终是一个字符串,对不同的操作数,它返回不同的结果. 此表总结了typeof所有可能的返回值: 操作数类型 返回值 undefined &qu ...

  4. tesseract-ocr识别英文和中文图片文字以及扫描图片实例讲解

    本文来源:http://blog.csdn.net/wanghui2008123/article/details/37694307 本文参考http://blog.sina.com.cn/s/blog ...

  5. hibernate 增改查后对象的三种状态转换

    this.getSession().update(obj); this.getSession().merge(obj); this.getSession().saveOrUpdate(obj);1. ...

  6. "二分法"-"折半法"-查找算法-之通俗易懂,图文+代码详解-java编程

    转自http://blog.csdn.net/nzfxx/article/details/51615439 1.特点及概念介绍 下面给大家讲解一下"二分法查找"这个java基础查找 ...

  7. 【gcd+stl】UVa1642 Magical GCD

    Description 一个长度为n的数列,选一个连续子序列,使得子序列的公约数*长度最大,求这个最大值.n<=1e5. Solution 连续子序列一般都要用滑动窗口是吧(固定r,快速计算最优 ...

  8. Charles 连接手机抓包出现Unknown,一直无法抓包的问题解决

    mac电脑安装了charles并且确保已经安装成功,https抓包需要安装的相关的证书已经安装,并且手机浏览器中输入chls.pro/ssl已经将证书下载完成,但是手机与电脑相连通过点击手机应用还是无 ...

  9. 【工具篇】接口测试神器 -- Postman 入门教程

    一.Postman概述 (1)工具介绍 Postman是一个接口测试工具,一款非常流行的API调试工具.在做接口测试的时候,Postman相当于一个客户端,它可以模拟用户发起的各类HTTP请求,将请求 ...

  10. 从壹开始前后端分离 42 ║支持多种数据库 & 快速数据库生成

    缘起 哈喽大家周三好,休息了一段时间,打算准备找工作了