ablog

不器用で落着きのない技術者のメモ

SQLHCのススメ

SQLHCとは

  • SQLチューニング・ヘルス・チェック・スクリプト(SQLHC)は My Oracle Support で提供されているPL/SQLスクリプト
  • My Oracle Support の DocID: 1542531.1 から sqlhc.zip をダウンロード・解凍して、sqlplus で SQL_ID を指定して実行
  • 指定した SQL_ID の実行計画、実行時間、参照している表・索引定義、統計情報、実行計画のボトルネックSQL監視、Optimizer(10053)トレース などを V$ASH、DBA_HIST_ASH、DBA_HIST_SQLSTAT などからまるっととってくれる便利スクリプト

情報採取手順

  • 情報採取する SQLSQL ID を確認する
  • DBサーバの任意のディレクトリで SQLHC を解凍する
$ unzip sqlhc.zip
Archive:  sqlhc.zip
   creating: sqlhc/
  inflating: sqlhc/sqlhc.sql
  inflating: sqlhc/sqldx.sql
  inflating: sqlhc/sqlhcxec.sql
$ cd sqlhc
  • データベースにログインし、SQLHC を実行する
$ sqlplus / as sysdba
SQL> @sqlhc T ftg35mrxs800v
# "T" はオプション(T:Tuning Pack ライセンス有、D: Diag Pack ライセンス有、N:ライセンス無)、"ftg35mrxs800v" は SQL ID
(中略)
Archive:  sqlhc_20160524_223403_94qn6y14kw01g.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     7187  05-24-2016 22:34   sqlhc_20160524_223403_94qn6y14kw01g_1_health_check.html
   114443  05-24-2016 22:34   sqlhc_20160524_223403_94qn6y14kw01g_2_diagnostics.html
    11087  05-24-2016 22:34   sqlhc_20160524_223403_94qn6y14kw01g_3_execution_plans.html
     5452  05-24-2016 22:35   sqlhc_20160524_223403_94qn6y14kw01g_4_sql_detail.html
    23474  05-24-2016 22:35   sqlhc_20160524_223403_94qn6y14kw01g_9_log.zip
    83925  05-24-2016 22:35   sqlhc_20160524_223403_94qn6y14kw01g_8_sqldx.zip
---------                     -------
   245568                     6 files
SQL> exit
$ ls -lh
(中略)
-rw-r--r-- 1 oracle oinstall 131K  524 22:35 2016 sqlhc_20160524_223403_94qn6y14kw01g.zip ★

以下のスライドの P.31-33 で分析例を少し紹介しています。

参考

Oracle SQL Tuning with Oracle SQLTXPLAIN: Oracle Database 12c Edition

Oracle SQL Tuning with Oracle SQLTXPLAIN: Oracle Database 12c Edition

What’s the Story of SQLT?
They say that necessity is the mother of invention, and that was certainly the case with SQLT. Oracle support engineers handle a huge number of tuning problems on a daily basis; problem is, the old methods of linear analysis are just too slow. You need to see the big picture fast so you can zoom in on the detail and tell the customer what’s wrong. As a result, Carlos Sierra, a support engineer at the time (now a member of the Oracle Center of Expertise—a team of experts within Oracle) created SQLT. The routines evolved over many visits to customer sites to a point where they can gather all the information required quickly and effectively. He then provided easy-to-use procedures for reporting on those problems.
Carlos Sierra, the genius of SQLT, now spends much of his time improving SQLT code and adapting the SQLT code to new versions of the RDBMS. He also assists Oracle Tuning Performance engineers with SQL tuning through the medium of SQLT.