数据库
首页 > 数据库> > SQL性能健康检查脚本 (SQLHC)(文档 ID 1626277.1)

SQL性能健康检查脚本 (SQLHC)(文档 ID 1626277.1)

作者:互联网

SQL性能健康检查脚本 (SQLHC)(文档 ID 1626277.1)

对于SQLHC(SQL Health Check,SQL性能健康检查脚本)工具,Mos文档1626277.1有非常详细的介绍。SQLHC是Oracle Server Technologies Center of Expertise开发的一个工具。SQLHC用于检查单条SQL语句运行的环境,包括基于成本的优化器(CBO)的统计数据,用户对象的元数据定义,配置参数和其它可能影响到目标SQL性能的因素。SQLHC和SQLT工具一样,本身都是免费的,不需要任何许可证(License)。当对某一个SQL_ID运行SQLHC后,该脚本会生成一系列针对该SQL语句健康检查的一份HTML报告。SQLHC会检查的内容包括:① 待分析的单条SQL涉及的用户对象的CBO统计信息;② CBO参数;③ CBO系统统计信息;④ CBO数据字典统计信息;⑤ CBO固定对象(Fixed-Objects)统计信息。

SQLHC运行时不会在数据库中创建任何对象(“数据库中不留足迹”),它只是对已有的对象提供报告和建议,可以确保它在所有系统上运行。SQLHC的脚本需要以SYS、DBA或者能访问数据字典视图的用户通过SQL*Plus连接运行。SQLHC一共包含3个脚本,分别为sqlhc.sql、sqldx.sql和sqlhcxec.sql,其中sqlhc.sql里边会调用sqldx.sql脚本。sqlhcxec.sql是单独执行的,不过该脚本需要输入一个脚本文件作为入参,而且该脚本文件可以包含绑定变量,但是必须要有“/* ^^unique_id */”注释,可以包含其它的Hint,如下所示:

点击(此处)折叠或打开

  1. REM Sample SCRIPT to be used as input to sqltxecute.sql
  2. REM

  3. -- execute sqlt xecute as sh passing script name
  4. -- cd sqlt
  5. -- #sqlplus sh
  6. -- SQL> start run/sqltxecute.sql input/sample/script1.sql

  7. REM Optional ALTER SESSION commands
  8. REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  9. --ALTER SESSION SET statistics_level = ALL;

  10. REM Optional Binds
  11. REM ~~~~~~~~~~~~~~

  12. VAR b1 NUMBER;
  13. EXEC :b1 := 10;

  14. REM SQL statement to be executed
  15. REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  16. SELECT /*+ gather_plan_statistics monitor bind_aware */
  17.        /* ^^unique_id */
  18.        s1.channel_id,
  19.        SUM(p.prod_list_price) price
  20.   FROM products p,
  21.        sales s1,
  22.        sales s2
  23.  WHERE s1.cust_id = :b1
  24.    AND s1.prod_id = p.prod_id
  25.    AND s1.time_id = s2.time_id
  26.  GROUP BY
  27.        s1.channel_id;
  28. /
  29. /

  30. REM Notes:
  31. REM 1. SQL must contain token: /* ^^unique_id */
  32. REM 2. Do not replace ^^unique_id with your own tag.
  33. REM 3. SQL may contain CBO Hints, like:
  34. REM /*+ gather_plan_statistics monitor bind_aware */


sqlhcxec  .  sql:  

点击(此处)折叠或打开

  1. REM EXAMPLE
  2. REM # sqlplus / as sysdba
  3. REM SQL> START [path]sqlhcxec.sql [T|D|N] [path]scriptname
  4. REM SQL> START utl/sqlhcxec.sql T input/sample/script1.sql


sqlhc.sql:

点击(此处)折叠或打开

  1. REM PARAMETERS
  2. REM 1. Oracle Pack license (Tuning or Diagnostics or None) T|D|N
  3. REM 2. SQL_ID of interest.
  4. REM
  5. REM EXECUTION
  6. REM 1. Start SQL*Plus connecting as SYS or user with DBA role or
  7. REM user with access to data dictionary views.
  8. REM 2. Execute script sqlhc.sql passing values for parameters.
  9. REM
  10. REM EXAMPLE
  11. REM # sqlplus / as sysdba
  12. REM SQL> START [path]sqlhc.sql [T|D|N] [SQL_ID]
  13. REM SQL> START sqlhc.sql T 51x6yr9ym5hdc









SQL 性能健康检查脚本 (SQLHC) (文档 ID 1626277.1)
         

文档详细信息

     


通过电子邮件发送此文档的链接在新窗口中打开文档可打印页

类型: 状态: 上次主更新: 上次更新: 语言:

SCRIPT PUBLISHED 2015-6-23 2016-9-16 English简体中文日本語???

 

  



文档内容  



用途
 下载 SQL Tuning Health-Check Script
 什么是 SQL Tuning Health-Check Script? (SQLHC)
 Licensing (SQLHC本身是免费的,不需要任何license)
 SQLHC总体概述
 最佳实践
 主动预防问题和诊断信息收集
 问题咨询,获取帮助,分享您对此文章的经验

要求

配置

说明

Script

示例输出

参考


适用于:

Oracle Database - Enterprise Edition - 版本 10.2.0.1 和更高版本  
Oracle Database Products > Oracle Database Suite > Oracle Database  
Oracle Database - Standard Edition - 版本 10.2.0.1 和更高版本  
Oracle Database - Personal Edition - 版本 10.2.0.1 和更高版本  
本文档所含信息适用于所有平台  

用途

 

下载 SQL Tuning Health-Check Script

SQL Health Check

在这里下载 SQLHC Script。


 

什么是 SQL Tuning Health-Check Script? (SQLHC)

SQL Tuning Health-Check Script 是 Oracle Server Technologies Center of Expertise 开发的一个工具。该工具也被称为 SQLHC,用于检查单条 SQL 语句运行的环境,包括基于成本的优化器(CBO)的统计数据,用户对象的元数据定义,配置参数和其他可能影响到待分析 SQL 性能的因素。

 

Licensing (SQLHC本身是免费的,不需要任何license)

就像上面提到的,SQLHC本身是免费的,不需要任何license. 
如果Diagnostic或者Tuning pack已经安装了, SQLHC会收集AWR中的信息,因此它会询问是否Diagnostic或者Tuning pack已经获得了license. 关于更详细的信息,请参照SQLHC FAQ的 licensing 部分:

Document 1454160.1 FAQ: SQL Health Check (SQLHC) Frequently Asked Questions


 

SQLHC总体概述

如下是一个对 SQLHC 总体概述的视频资料:

Document 1455583.1 SQL Tuning Health-Check Script (SQLHC) Video


SQLHC 的初衷是通过确保某一个 SQL 的运行环境合理,从而帮助用户规避一些可避免的 SQL 性能问题。

SQLHC 运行时不会在数据库中创建任何对象(“数据库中不留足迹”),确保它可以在所有系统上运行。

当对某一个 SQL_ID 运行 SQLHC 后,该脚本会生成一系列针对该 SQL 语句健康检查的一份 HTML 报告。您可以通过 AWR/ASH 或者查询 V$SQL 得到 SQL 语句的 SQL_ID:

Document 1627387.1 How to Determine the SQL_ID for a SQL Statement

健康检查会在如下方面执行:

注意:您可以在如下地址找到一篇题为"How to Improve SQL Performance with the New Health Check Tool?"的视频录像,以及一些其他的视频录像:  

Document 740964.1 Advisor Webcast Archived Recordings


您可以在如下地址找到 SQL Healthcheck script 的 FAQ:  

Document 1417774.1 FAQ: SQLHC HealthCheck Frequently Asked Questions


此外,我们欢迎您提出更多的健康检查建议。  
如果您需要一些特殊的健康检查但是在 SQLHC 中没有包含,只要该健康检查可以通过一条 SQL 命令实现(数据库中不留足迹),那么我们可以考虑在今后的版本中实现。  

如果有需要补充的内容,请在此文章中添加评论。


 

最佳实践

 

主动预防问题和诊断信息收集

尽管一些问题是不可预料的,在很多时候,如果迹象发现及时,这些问题是可以避免的。另外,如果问题真的发生了,事后收集该问题的信息是没有用的。SQLHC 是一种技术支持推荐的收集这些信息的工具。关于使用建议,其他的前提准备和诊断,参考:

Document 1482811.1 Best Practices: Proactively Avoiding Database and Query Performance Issues  
Document 1477599.1 Best Practices Around Data Collection For Performance Issues

 

问题咨询,获取帮助,分享您对此文章的经验

您想和其他 Oracle 客户,Oracle 雇员和行业专家来进一步探讨该主题么?

请点击这里加入讨论,您可以咨询问题,获得其他人的帮助,分享您对这边文章的经验。
点击这里访问 My Oracle Support Community 数据库调优主页来发现对其他文章和主题的讨论

要求

以 SYS, DBA 或者能访问数据字典视图的用户通过 SQL*Plus 连接运行此脚本。

注意:该脚本不会在数据库中创建任何对象,它只是对已有的对象提供报告和建议。

配置

不需要任何配置。

说明

  1. 登录数据库服务器并且设置数据库实例环境变量
  2. 下载 "sqlhc.zip" 并解压到一个合适的目录
  3. 以 SYS, DBA 或者能访问数据字典视图的用户通过 SQL*Plus 连接并执行该脚本,需要输入两个参数

    1. Oracle Pack License (Tuning, Diagnostics or None) [T|D|N] (required)
      如果有 Tuning and Diagnostics licenses 那么输入 T(指 Oracle Tuning pack,包括 Oracle Diagnostics)

    2. 待分析的 SQL 的有效 SQL_ID 

例如:

# sqlplus / as sysdba  
SQL> START sqlhc.sql T djkbyr8vkc64h


警告

此示例代码只为教育目的,Oracle Support不提供技术支持。它已经过内部测试,然而我们无法确保它在任何环境中都能成功使用。请您在使用之前先在测试环境中运行。  

SCRIPT

在这里下载 SQLHC Script。

示例输出

downloadattachmentprocessor?parent=DOCUMENT&sourceId=1626277.1&attachid=1366133.1:SQLHC_Example1&clickstream=yes

参考

NOTE:1460440.1   - Script PXHCDR.SQL: Parallel Execution Health-Checks and Diagnostics Reports  
NOTE:1417774.1   - FAQ: SQL Health Check (SQLHC) Frequently Asked Questions  
NOTE:224270.1   - TRCANLZR (TRCA): SQL_TRACE/Event 10046 Trace File Analyzer - Tool for Interpreting Raw SQL Traces  
NOTE:1477599.1   - Best Practices: Proactive Data Collection for Performance Issues  
NOTE:1455583.1   - SQL Tuning Health-Check Script (SQLHC) Video  
NOTE:215187.1   - SQLT Diagnostic Tool  
NOTE:243755.1   - Script to produce HTML report with top consumers out of PL/SQL Profiler DBMS_PROFILER data  
NOTE:1482811.1   - Best Practices: Proactively Avoiding Database and Query Performance Issues  




FAQ: SQL Health Check (SQLHC) Frequently Asked Questions (文档 ID 1417774.1)  

 文档详细信息 

通过电子邮件发送此文档的链接在新窗口中打开文档可打印页

类型: 状态: 上次主更新: 上次更新:

FAQPUBLISHED2016-11-32016-11-3


In this Document


Purpose

Questions and Answers
 Background and Structure
 What is the SQL Tuning Health-Check Script?
 What is the origin of SQLHC?
 Is SQLHC an 'advanced' version of SQLTXPLAIN?
 Are the underlying selects used by SQLHC available?
 Setup and Usage
 Where can SQLHC be downloaded from?
 How can I identify the SQL I want to Healthcheck?
 Does SQLHC have to execute the SQL to generate a report?
 What if the SQL_ID in question has been aged out from memory?
 Can SQLHC retrieve an explain plan from memory or the AWR?
 Is SQLHC safe to use in a production environment?
 Is SQLHC practical to use for complex sql statements?
 Part of the sqlhc.sql script that inserts rows into the plan_table, but the documentation states that SQLHC Leaves "no database footprint". How can this be the case?
 The SQLHC Documentation states that there is no configuration required, but it does not state how to create the 'plan_table'. How can I create the plan_table?
 Compatible Versions and licensing
 Is the SQLHC script the same for all versions?
 Can SQLHC be used on Oracle 9i or below?
 What is the licensing requirement for SQLHC?
 What is missing from the report if the Tuning Pack is not installed?
 When using SQLHC, is it more beneficial to have AWR than not having AWR?
 Are the global health checks specific to any version of Oracle?
 Software Compatibility
 Does SQLHC work with --Insert application here--
 Are there any limitations on using this script in a Database running EBusiness Suite?
 Is it practical to use this tool for SAP?
 Does this SQL Health Check tool take into consideration that the query is executed on an Exadata system/database ?
 Are there any Exadata specific settings?
 Can this tool be used with Data Guard?
 How we can integrate this script in to GridControl?
 Are there specific checks related to Peoplesoft?
 Are there specific checks related to Siebel?
 Compatibility with Specific Database Features
 Can SQLHC be used on a remote database?
 Can SQLHC be used on SQL that accesses a remote database?
 Does SQLHC work with XML Type and XML indexes?
 Does it work with encrypted columns?
 Does SQLHC work with LOB columns?
 Does SQLHC advise for extended statistic or index reordering?
 Is SQLHC RAC aware?
 Can I use SQLHC to analyze a call to a pl/sql procedure?
 Is there a way to run without having to execute the SQL (like EXPLAIN PLAN?)
 Does SQLHC show multiple plans from the SQL Tuning Advisor?
 What is the difference between SQLHC and --Insert application here--
 How does SQLHC differ from SQLT?
 What is the difference between SQLHC and AWR and TKProf?
 Checks related to Statistics
 SQLHC mentions some issues with system statistics. Are system statistics supposed to be gathered?
 Are statistics on dictionary objects supposed to be gathered?
 Are statistics required on temporary tables?
 Can the tool determine whether statistics were gathered using ANALYZE instead of DBMS_STATS
 Since 11g Oracle automates the statistics collection, why is the script checking for statistics health?
 Does SQLHC use just the most recent statistics for health check?
 If the statistics have been locked, then will SQLHC give the desired results?
 Questions regarding specific checks performed
 SQLHC says that Value A is greater than Value B. This is impossible. How can this have occurred?
 If a collective parameter such as "OPTIMIZER_FEATURES_ENABLE" has been set, does SQLHC just report on that parameter change or on all the affected underlying parameters?
 Miscellaneous Questions
 Does SQLHC show all the checks done or just the results that are non-compliant?
 Is the "Tables" and "Indexes Summary" for all tables or only for the tables affected by a particular SQL?
 Does SQLHC check the dictionary statistics against the actual values in the objects?
 Does the health check account for bind variables in any way?
 Will SQLHC tell you that the same SQL is used with different plans ?
 Can the health check script help me identify changes to the explain plan over a long period of time?
 Does SQLHC provide any advise to improve the performance or is it just a health check?
 Does SQLT provide SQL recommendations or does it only Provide the Execution plan?
 Is SQLHC able to identify disk I/O performance issues?
 How is it best to use the information provided by SQLHC?
 Does SQLHC take into account session parameter changes as well as global ones?
 Could SQLHC not be integrated with advisor tools rather than having multiple tools?

References


APPLIES TO:

Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.3 [Release 10.1 to 11.2]  
Information in this document applies to any platform.  

PURPOSE

SQL Health Check

This document answers some of the frequently asked questions about the SQLHC tool.

NOTE: We welcome any additional health-checks that you may suggest. If any specific health-checks are needed and not covered by this script, then as long as the health-check can be produced with a SQL Command (leaving no database footprint ) then these can be implemented in future versions.  

Please add comments to this Document or to:   

Document 1366133.1 SQL Tuning Health-Check Script (SQLHC)


for any desired additions.


QUESTIONS AND ANSWERS

 

Background and Structure

 

Setup and Usage

 

Compatible Versions and licensing

 

Software Compatibility

 

Compatibility with Specific Database Features

 

What is the difference between SQLHC and --Insert application here--

For specific details of a number of performance related database features, see:

Document 1361401.1 Where to Find Information About Performance Related Features


 

Checks related to Statistics

 

Questions regarding specific checks performed

 

Miscellaneous Questions


REFERENCES


NOTE:1366133.1   - SQL Tuning Health-Check Script (SQLHC)  
NOTE:1455583.1   - SQL Tuning Health-Check Script (SQLHC) Video  
NOTE:1627387.1   - How to Determine the SQL_ID for a SQL Statement  


标签:statistics,Tuning,AWR,SQL,SQLHC,Document,1626277.1
来源: https://blog.51cto.com/lhrbest/2698353