SQLT

SQLTXPLAIN (SQLT) 是Oracle专家开发的,用于诊断SQL相关的问题的工具,简单易用却功能强大。

SQLT 会用户根据指定的模式,连接到数据库,收集执行计划、基于成本的 Optimizer CBO 统计信息、Schema 对象元数据、性能统计信息、配置参数和会影响正在分析的 SQL 性能的其他元素。

如果是SQL相关问题,建议通过SQLT收集信息,这样在定位问题以及和Oracle官方技术支持交互过程会减少很多不必要的时间和确认。

SQLT安装

通过 官方MOS Document 215187.1 可以下载最新的SQLT安装包,下载后通过安装中sqlt_instructions.html的介绍,按以下步骤可以安装好SQLT。

例:(12c NONCDB @Linux)

1.对SQLT安装包(sqlt_latest.zip)解压

[oracle@db12102 20160827]$ ls
sqlt_latest.zip
[oracle@db12102 20160827]$ unzip sqlt_latest.zip
Archive:  sqlt_latest.zipcreating: sqlt/creating: sqlt/doc/
...inflating: sqlt/utl/xplore/xplore.pks
[oracle@db12102 20160827]$ ls
sqlt  sqlt_latest.zip

2.进入sqlt的路径,准备安装

[oracle@db12102 20160827]$ cd sqlt
[oracle@db12102 sqlt]$ ls
doc  input  install  run  sqlt_instructions.html  sqlt_instructions.txt  utl

3.执行sqcreate.sql进行安装

SQL> conn /as sysdba
Connected.
SQL> @install/sqcreate.sql

在安装过程中需要指定的参数和各参数的含义如下:

3-1.连接标识符(当安装在一个可插拔数据库上时是必须的)

Specify optional Connect Identifier (as per Oracle Net)
Include "@" symbol, ie. @PROD
If not applicable, enter nothing and hit the "Enter" key.
You *MUST* provide a connect identifier when installing
SQLT in a Pluggable Database in 12c
This connect identifier is only used while exporting SQLT
repository everytime you execute one of the main methods.Optional Connect Identifier (ie: @PROD):

3-2.SQLTXPLAIN 密码

Define SQLTXPLAIN password (hidden and case sensitive).
Password for user SQLTXPLAIN:

3-3.SQLTXPLAIN 默认表空间

The next step is to choose the tablespaces to be used by SQLTXPLAIN
The Tablespace name is case sensitive.
Do you want to see the free space of each tablespace [YES]
or is it ok just to show the list of tablespace [NO]?Type YES or NO [Default NO]: NO  ... please waitTABLESPACE                     FREE_SPACE_MB
------------------------------ -------------
EXAMPLE
USERSSpecify PERMANENT tablespace to be used by SQLTXPLAIN.
Tablespace name is case sensitive.
Default tablespace [UNKNOWN]: USERSPL/SQL procedure successfully completed.
... please waitTABLESPACE
------------------------------
TEMPSpecify TEMPORARY tablespace to be used by SQLTXPLAIN.
Tablespace name is case sensitive.
Temporary tablespace [UNKNOWN]: TEMP

3-4. 应用程序用户 (发出要分析 SQL 语句的用户)

The main application user of SQLT is the schema
owner that issued the SQL to be analyzed.
For example, on an EBS application you would
enter APPS.
You will not be asked to enter its password.
To add more SQLT users after this installation
is completed simply grant them the SQLT_USER_ROLE
role.Main application user of SQLT: teacherwhat

※也可以在安装该工具后添加其他的 SQLT 用户,方法为:授予他们角色 SQLT_USER_ROLE, 或通过使用提供的脚本 sqlt/install/sqguser.sql

例:
SQL> conn /as sysdba
SQL> @install/sqguser.sql scott

3-5. 授权的 Oracle Pack。(T,D 或 N)

SQLT can make extensive use of licensed features
provided by the Oracle Diagnostic and the Oracle
Tuning Packs, including SQL Tuning Advisor (STA),
SQL Monitoring and Automatic Workload Repository
(AWR).
To enable or disable access to these features
from the SQLT tool enter one of the following
values when asked:"T" if you have license for Diagnostic and Tuning
"D" if you have license only for Oracle Diagnostic
"N" if you do not have these two licensesOracle Pack license [T]: T

4.如果需要的话,通过下面的脚本可以卸载 SQLT。

SQL> conn /as sysdba
SQL> @install/sqdrop.sql

※卸载 SQLT 会同时移除 SQLT Repository 以及所有SQLT相关的内容。

参考:
All About the SQLT Diagnostic Tool (Doc ID 215187.1)

SQLT的使用

执行方法的种类

SQLT的执行方法主要包括以下

XTRACT:通过V$SQL、AWR的过去执行过的SQL内容,收集相关信息。
XECUTE:通过执行SQL,收集相关信息。XPLAIN:不执行SQL,基于EXPLAIN PLAN FOR命令收集相关信息。(不推荐)
XTRXEC:该方法合并了XTRACT和XECUTE 的功能。实际上,XTRXEC连续执行了这两种方法。
XTRSBY:分析在 Data Guard 或备用只读数据库上执行的 SQL。
XPREXT:使用XTRACT同时禁用一些SQLT的特性,使之执行更快。
XPREXC:使用XECUTE同时禁用一些SQLT的特性,使之执行更快

执行方法

XTRACT 方法

通过V$SQL、AWR的过去执行过的SQL内容,收集相关信息。

1.通过V$SQL或AWR找到要收集数据的SQL的SQL_ID 或者HASH_VALUE。

SELECT sql_id, hash_value, SUBSTR(sql_text,1,40) Text
FROM v$sql
WHERE sql_text LIKE '%&An_Identifiable_String%';

2.进入到sqlt的run路径下,执行sqltxtract.sql脚本收集相关信息

$ ls
doc  input  install  run  SQLT_installation_logs_archive.zip  sqlt_instructions.html  sqlt_instructions.txt  utl
$ cd run
$sqlplus Username/Password
SQL> START sqltxtract.sql [SQL_ID]|[HASH_VALUE] [sqltxplain_password]

3.执行例:

[oracle@db12102 sqlt]$ ls
doc  input  install  run  SQLT_installation_logs_archive.zip  sqlt_instructions.html  sqlt_instructions.txt  utl
[oracle@db12102 sqlt]$ cd run
[oracle@db12102 run]$ sqlplus /nolog     SQL*Plus: Release 12.1.0.2.0 Production on Sat Aug 27 20:18:29 2016Copyright (c) 1982, 2014, Oracle.  All rights reserved.SQL> conn teacherwhat/teacherwhat
Connected.
SQL> select/*+ GATHER_PLAN_STATISTICS MONITOR */ count(*) from SQLMON where a='A';COUNT(*)
----------1000SQL> SELECT sql_id, hash_value, SUBSTR(sql_text,1,40) Text
FROM v$sql
WHERE sql_text LIKE 'select/*+ GATHER_PLAN_STATISTICS MONITOR */ count(*)%';  2    3  SQL_ID        HASH_VALUE
------------- ----------
TEXT
--------------------------------------------------------------------------------
acsdndc43qs74  138109156
select/*+ GATHER_PLAN_STATISTICS MONITORSQL> START sqltxtract.sql acsdndc43qs74 SQLTXPLAIN
... adding: sqlt_s28359_sqldx.zip (stored 0%)#####
The SQLT has collected information and place it in a repository in the database, exported it and zip it.
The collected info can be purged from the database using the following file :
... getting sqlt_s28359_purge.sql out of sqlt repository ...SQLTXTRACT completed.

相关的信息生成在了sqlt_s28359_sqldx.zip 中。

XECUTE 方法

通过执行SQL,收集相关信息;与 XTRACT方法相比,该方法提供的信息更为详细.

1.使用XECUTE 方法之前,创建一个包含 SQL 文本的文本文件。
如果 SQL 包括绑定变量,则您的文件必须包含绑定变量声明和赋值。

 例:target.sql-----------------------select/*+ GATHER_PLAN_STATISTICS MONITOR */ count(*) from SQLMON where a='A';-----------------------

2.执行sqltxecute.sql脚本收集相关信息

$cd sqlt/run
$sqlplus Username/Password
SQL> START [path]sqltxecute.sql [path]scriptname [sqltxplain_password]

3.执行例

[oracle@db12102 run]$ vi target.sql
[oracle@db12102 run]$ more target.sql
select/*+ GATHER_PLAN_STATISTICS MONITOR */ count(*) from SQLMON where a='A';
[oracle@db12102 run]$ sqlplus / as sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Sat Aug 27 21:06:09 2016Copyright (c) 1982, 2014, Oracle.  All rights reserved.Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing optionsSQL> conn teacherwhat/teacherwhat
Connected.
SQL>  START sqltxecute.sql target.sql SQLTXPLAIN
...adding: sqlt_s28360_sqldx.zip (stored 0%)#####
The SQLT has collected information and place it in a repository in the database, exported it and zip it.
The collected info can be purged from the database using the following file :
... getting sqlt_s28360_purge.sql out of sqlt repository ...SQLTXECUTE completed.
其他方法

其他方法可以参考SQLT安装包中的【sqlt_instructions.html】中的介绍。

使用SQLT的注意事项

  1. SQLT xecute MODE 不能针对DDL文取得信息,否者会报ORA-01086错误

    例:[oracle@db12102 run]$ cat target.sql
    create table testttt as select * from emp;SQL> START sqltxecute.sql target.sql SQLTXPLAIN■sqltxecute2.log
    ...SQL>SET TERM ON ECHO OFF;To monitor progress, login into another session and execute:
    SQL> SELECT * FROM SQLTXADMIN.sqlt$_log_v;... collecting diagnostics details, please wait ...In case of a disconnect review log file in current directory
    If running as SYS in 12c make sure to review sqlt_instructions.html first1* create table testttt as select * from empPREV_SQL_ID                             PREV_CHILD_NUMBER
    --------------------------------------- -----------------
    22ygsf8vfyk2f                                           0
    経過: 00:00:00.21
    ROLLBACK TO SAVEPOINT sqlt_xecute_savepoint
    *
    行1でエラーが発生しました。:
    ORA-01086: セーブポイント'SQLT_XECUTE_SAVEPOINT'はこのセッションで設定されていないか、無効です
    

2.可以针对DDL文取得XTRACT MODE的信息

    例:SQL> create table testttt as select * from emp;SQL> SELECT sql_id, hash_value, SUBSTR(sql_text,1,40) TextFROM v$sqlWHERE sql_text LIKE '%create table testttt%'; SQL_ID                                  HASH_VALUE--------------------------------------- ----------TEXT--------------------------------------------------------------------------------22ygsf8vfyk2f                            921651278create table testttt as select * from emSTART sqltxtract.sql 22ygsf8vfyk2f  SQLTXPLAIN

版权声明:本文为博主原创文章,转载必须注明出处,本人保留一切相关权力!http://blog.csdn.net/lukeunique

欢迎关注微信订阅号:TeacherWhat

【SQL工具】SQL调优和诊断神器SQLTXPLAIN (SQLT)简介相关推荐

  1. SQL Server 性能调优(cpu)

    SQL Server 性能调优(cpu) 研究cpu压力工具 perfom SQL跟踪 性能视图 cpu相关的waitevent Signal wait time SOS_SCHEDULER_YIEL ...

  2. SQL Server性能调优入门(图文版)

    第一步,在业务高峰期抓取样本数据(2个小时左右).采用的工具是sqlserver自带的profiler,也叫事件探查器,如下图: 进入后,点击最左面的按钮,建立一个新的跟踪: 登录需要用DBO权限,所 ...

  3. SQL Server 性能调优(方法论)

    SQL Server 性能调优(方法论) 目录 确定思路 wait event的基本troubleshooting 虚拟文件信息(virtual file Statistics) 性能指标 执行计划缓 ...

  4. SQL Server 性能调优3 之索引(Index)的维护

    SQL Server 性能调优3 之索引(Index)的维护 热度1 评论 16 作者:溪溪水草 SQL Server 性能调优3 之索引(Index)的维护 前言 前一篇的文章介绍了通过建立索引来提 ...

  5. SQL Server性能调优之执行计划深度剖析 第二节 执行计划第一次实践

    SQL Server性能调优之执行计划深度剖析 第二节 执行计划第一次实践 前言:自从上一篇文章发出之后,收到了很朋友的关注.很多朋友要求多多实践,而不是纯粹的理论.确实,从打算出这个系列开始,我就本 ...

  6. sql server 性能调优之 资源等待 LCk

    一.  概述 这次介绍实例级别资源等待LCK类型锁的等待时间,关于LCK锁的介绍可参考 "sql server 锁与事务拨云见日".下面还是使用sys.dm_os_wait_sta ...

  7. jvm调优五:jvm调优工具和调优实战

    jvm调优工具和调优实战 jvm自带常用命令 JPS jps是用于查看有权访问的hotspot虚拟机的进程id. 当未指定hostid时,默认查看本机jvm进程id -l:输出完整jar名称 -v:输 ...

  8. Java性能压测工具及其调优

    Java性能压测工具及其调优 JMeter工具 使用 JVisualVM使用 使用 简介 在日常的开发中,Java的性能显得尤为重要,一个程序的好坏主要就是性能来决定的. JMeter工具 JMete ...

  9. 《Oracle高性能SQL引擎剖析:SQL优化与调优机制详解》一1.1 生成执行计划

    1.1 生成执行计划 在Oracle中,任何一条语句在解析过程中都会生成一个唯一的数值标识,即SQL_ID.而同一条语句,在解析过程中,可能会因为执行环境的改变(例如某些优化参数被改变)而生成多个版本 ...

最新文章

  1. VC++ error C2248: “CObject::CObject”: 无法访问 private 成员(在“CObject”类中声明)
  2. 7-4 递增序列 (15 分)
  3. SQL注入法攻击一日通
  4. c语言音像店程序,音像店管理程序_C 课程设计.pdf
  5. c语言去空格换行符,关于文件操作,碰到空格就换行
  6. WordPress主题LensNews模板源码,2.2版本多功能新闻积分商城主题
  7. 源码分析参考:Pipelines
  8. Spring Validation校验
  9. html里,实现图片与文字对齐的最简洁方法
  10. linux连接FreeBSD虚拟机的mysql
  11. bean的作用域_Spring 框架基础(02):Bean的生命周期,作用域,装配总结
  12. Realm Swift
  13. 图片剪裁控件——ClipImageView
  14. 力扣-605 种花问题
  15. matlab好看的字体,[转载]最合适写代码的字体
  16. IDEA提示“Spring Configuration Check“ “Unmapped Spring configuration files found.“
  17. 【Cloudaily】3.15五招教你辨别真假云计算,2017 Gartner数据科学魔力象限出炉
  18. linux新建用户和目录权限设置密码,用户创建及权限管理
  19. Windows Server 中 DNS 服务器的新增功能
  20. CAD建筑制图入门加老虎窗

热门文章

  1. http://pan.baidu.com/share/link?shareid=372668uk=4076915866#dir/path=%2F%E5%AD%
  2. 超详细Kafka架构原理图(观止)
  3. NPAS:A Compiler-aware Framework of Unified Network Pruning and Architecture Search
  4. 蛛网时代:我们不一样!BI工具中的创新者
  5. android 源码编译core dumped,Ubuntu18.04 编译Android 8.1 源码出现的问题及解决笔记
  6. MySQL day1
  7. 运动神经元会导致肢体无力 肌肉酸痛吗
  8. 浅学PolSARPro软件
  9. 他心中的你,不一定是你 ——《定位》
  10. 流量为王,帅掌柜刷脸支付数据化“支付”,大数据,精运营