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,如下所示:
点击(此处)折叠或打开
- REM Sample SCRIPT to be used as input to sqltxecute.sql
- REM
-
- -- execute sqlt xecute as sh passing script name
- -- cd sqlt
- -- #sqlplus sh
- -- SQL> start run/sqltxecute.sql input/sample/script1.sql
-
- REM Optional ALTER SESSION commands
- REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- --ALTER SESSION SET statistics_level = ALL;
-
- REM Optional Binds
- REM ~~~~~~~~~~~~~~
-
- VAR b1 NUMBER;
- EXEC :b1 := 10;
-
- REM SQL statement to be executed
- REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- SELECT /*+ gather_plan_statistics monitor bind_aware */
- /* ^^unique_id */
- s1.channel_id,
- SUM(p.prod_list_price) price
- FROM products p,
- sales s1,
- sales s2
- WHERE s1.cust_id = :b1
- AND s1.prod_id = p.prod_id
- AND s1.time_id = s2.time_id
- GROUP BY
- s1.channel_id;
- /
- /
-
- REM Notes:
- REM 1. SQL must contain token: /* ^^unique_id */
- REM 2. Do not replace ^^unique_id with your own tag.
- REM 3. SQL may contain CBO Hints, like:
- REM /*+ gather_plan_statistics monitor bind_aware */
sqlhcxec . sql:
点击(此处)折叠或打开
- REM EXAMPLE
- REM # sqlplus / as sysdba
- REM SQL> START [path]sqlhcxec.sql [T|D|N] [path]scriptname
- REM SQL> START utl/sqlhcxec.sql T input/sample/script1.sql
sqlhc.sql:
点击(此处)折叠或打开
- REM PARAMETERS
- REM 1. Oracle Pack license (Tuning or Diagnostics or None) T|D|N
- REM 2. SQL_ID of interest.
- REM
- REM EXECUTION
- REM 1. Start SQL*Plus connecting as SYS or user with DBA role or
- REM user with access to data dictionary views.
- REM 2. Execute script sqlhc.sql passing values for parameters.
- REM
- REM EXAMPLE
- REM # sqlplus / as sysdba
- REM SQL> START [path]sqlhc.sql [T|D|N] [SQL_ID]
- REM SQL> START sqlhc.sql T 51x6yr9ym5hdc
SQL 性能健康检查脚本 (SQLHC) (文档 ID 1626277.1)
>>
>
|