`

oracle tkprof 分析sql执行计划

阅读更多

oracle   tkprof  分析sql执行计划

 

 

1)开启系统级sql追踪

alter system set sql_trace= true ;

select b.spid,a.sid,a.serial#,a.machine from v$session a,v$process b where a.paddr = b.addr and a.machine='yangyang(计算机名)';

 

----http://www.iteye.com/topic/19024  (部分引用)
SQL> select b.spid,a.sid,a.serial#,a.machine from v$session a,v$process b where a.paddr = b.addr and a.machine='yangyang'; 

SPID                SID    SERIAL#
------------ ---------- ----------
MACHINE
----------------------------------------------------------------
4007               5487          4
yangyang

4009               5483          1
yangyang

4013               5482          2
yangyang

SQL> execute sys.dbms_system.set_ev(49, 3406,10046,1,'');                                                       

SQL> execute sys.dbms_system.set_ev(5487,4,10046,1,'');

PL/SQL procedure successfully completed.

SQL> execute sys.dbms_system.set_ev(5487,4,10046,0,'');

 

获取本机

2) 访问数据库后,要关闭追踪

alter system set sql_trace= false ;

 

3)获得追踪计划保存的文件

SELECT    d.VALUE
       || '/'
       || LOWER (RTRIM (i.INSTANCE, CHR (0)))
       || '_ora_'
       || p.spid
       || '.trc' trace_file_name
  FROM (SELECT p.spid
          FROM v$mystat m, v$session s, v$process p
         WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
       (SELECT t.INSTANCE
          FROM v$thread t, v$parameter v
         WHERE v.NAME = 'thread'
           AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
       (SELECT VALUE
          FROM v$parameter
         WHERE NAME = 'user_dump_dest') d

可以制作成sql文件放在linux系统下 例如保存为 trace_sql.sql

 

@/home/netmessage/trace_sql.sql


SQL> @/home/netmessage/trace_sql.sql
 17  ;

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/admin/orcl/udump/orcl_ora_11822.trc

 

 

4)分析追踪计划 用tkprof (linux 下tkprof 报错,所以在xp下进行分析了一下,linux 找到tkprof 所在的bin 就可以了,应该是8i 以上 在oracle bin中有存在)

    C:\Documents and Settings\Administrator>tkprof d:\sql.trc d:\sql.txt

 

 

 

看一下执行计划的分析结果:

 

 


TKPROF: Release 10.2.0.1.0 - Production on 星期一 3月 26 18:39:22 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Trace file: d:\sql.trc
Sort options: default

********************************************************************************
count    = number of times OCI procedure was executed
cpu      = cpu time in seconds executing
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
********************************************************************************

alter system set sql_trace=true


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        0      0.00       0.00          0          0          0           0
Execute      1      0.00       0.06          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        1      0.00       0.06          0          0          0           0

Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
********************************************************************************

SELECT PT.VALUE
FROM
 SYS.V_$SESSTAT PT WHERE PT.SID=:1 AND PT.STATISTIC# IN (7,47,50,54,134,335,
  336,337,341,342) ORDER BY PT.STATISTIC#


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      0      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        1      0.00       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
********************************************************************************

select obj#,type#,ctime,mtime,stime,status,dataobj#,flags,oid$, spare1,
  spare2
from
 obj$ where owner#=:1 and name=:2 and namespace=:3 and remoteowner is null
  and linkname is null and subname is null


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.00       0.00          0          4          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.00       0.00          0          4          0           1

Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: SYS   (recursive depth: 1)

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  TABLE ACCESS BY INDEX ROWID OBJ$ (cr=4 pr=0 pw=0 time=71 us)
      1   INDEX RANGE SCAN I_OBJ2 (cr=3 pr=0 pw=0 time=50 us)(object id 37)

********************************************************************************

select cols,audit$,textlength,intcols,property,flags,rowid
from
 view$ where obj#=:1


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.00       0.00          0          3          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.00       0.00          0          3          0           1

Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: SYS   (recursive depth: 1)

 

********************************************************************************

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.06          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.00       0.06          0          0          0           0

Misses in library cache during parse: 1
Misses in library cache during execute: 1


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          0          7          0           2
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        6      0.00       0.00          0          7          0           2

Misses in library cache during parse: 0

    2  user  SQL statements in session.
    2  internal SQL statements in session.
    4  SQL statements in session.
********************************************************************************
Trace file: d:\sql.trc
Trace file compatibility: 10.01.00
Sort options: default

       2  sessions in tracefile.
       3  user  SQL statements in trace file.
       2  internal SQL statements in trace file.
       4  SQL statements in trace file.
       4  unique SQL statements in trace file.
      45  lines in trace file.
      82  elapsed seconds in trace file.

 

分享到:
评论

相关推荐

    Oracle高性能SQL调整

    资源名称:Oracle高性能SQL调整内容简介:本书由Oracle公司授权,向读者详尽阐述如何调整SQL语句、查看内部执行计划和更改执行计划以提高语句性能。主要内容包括:理解SQL调整在Oracle总体微调中地地位,使用诸如...

    《Oracle高性能SQL调整》

    使用语如内嵌视图和BIF扩展提高QraleSQL性能,确定并报告程序库缓存中的SQL语句,调整SQL表访问、完整表扫描和平行查询,运行TKPROF获得SQL跟踪报告,使用Oracle线索为OracleSQL语句更改执行计划,使用Oracle8i优化...

    ORACLE执行计划和SQL调优知识概述.pptx

    EXPLAIN PLAN 是一种分析执行计划的工具,可以帮助开发者了解 SQL 语句的执行计划和成本。SQL_TRACE 是一种追踪 SQL 语句执行的工具,可以帮助开发者了解 SQL 语句的执行时间和资源消耗。TKPROF 是一种格式化 SQL_...

    oracle高性能sql调整(全)

    理解SQL调整在Oracle总体微调中地地位,使用诸如内嵌视图和BIF扩展提高Oracle SQL性能,确定并报告程式库缓存中的SQL语句,调整SQL表访问、完整表扫描和平行查询,运行TKPROF获得SQL跟踪报告,使用Oracle线索 ...

    使用TKPROF 工具分析跟踪文件

    Tkprof 是一个用于分析Oracle 跟踪文件并且产生一个更加清晰合理的输出结果的可执行工具。如果一个 系统的执行效率比较低,一个比较好的方法是通过跟踪用户的会话并且使用Tkprof 工具使用排序功能格式 化输出,从而...

    大牛出手Oracle SQL优化实例讲解

    6.sql trace分析工具--TKPROF详细讲解 7.V$SQL视图详解加几个实例 8.autotrace验证压缩表性能 9.autotrace验证消除子查询后的性能 10.基于基本的优化CBO 11.如何统计数据库数据 12.Oracle如何统计操作系统数据 13./*...

    oracle高性能sql调整

    理解SQL调整在Oracle总体微调中地地位,使用诸如内嵌视图和BIF扩展提高Oracle SQL性能,确定并报告程式库缓存中的SQL语句,调整SQL表访问、完整表扫描和平行查询,运行TKPROF获得SQL跟踪报告,使用Oracle线索 ...

    SQL Trace and TKPROF

    SQL Trace and TKPROF

    Tkprof工具介绍和分析

    kprof是一个用于分析Oracle跟踪文件并且产生一个更加清晰合理的输出结果的可执行工具。如果一个系统的执行效率比较低,一个比较好的方法是通过跟踪用户的会话并且使用Tkprof工具使用排序功能格式化输出,从而找出有...

    Oracle PL/SQL PRofiler应用指南

    Profiler是ORACLE PL/SQL 的一个调试优化跟踪方案的应, 相对sqltrace+tkprof工具调试优化跟踪方案来说, Profiler有最直观更方便的优点,因为不需要生成和读取服务器端的跟踪文件,它是将跟踪数据全部存储的数据库...

    Oracle性能优化方法(SQL篇)

    1.如何分析SQL语句 2.选用适合的ORACLE优化器 3.用EXPLAIN PLAN 分析SQL语句 4.使用TKPROF 工具来查询SQL性能状态 5.表分区的应用

    让Oracle跑得更快 Oracle 10g性能分析与优化思路.part2.rar

    5.2 sql的执行计划 94 第6章 hint 109 6.1 和优化器相关的hint 115 6.1.1 all_rows和first_rows(cbo) 115 6.1.2 rule hint 117 6.2 访问路径相关的hint 117 6.2.1 full hint 118 6.2.2 index hint 118 6.2.3 no_...

    让Oracle跑得更快 Oracle 10g性能分析与优化思路.part1.rar

    5.2 sql的执行计划 94 第6章 hint 109 6.1 和优化器相关的hint 115 6.1.1 all_rows和first_rows(cbo) 115 6.1.2 rule hint 117 6.2 访问路径相关的hint 117 6.2.1 full hint 118 6.2.2 index hint 118 6.2.3 no_...

    tkprof格式详解

    详解tkprof转换后的文件格式,用于SQL语句的分析和性能调优

    sqlmonitor

    sqlmonitor 1. 找出sid和serial# select sid,serial#,osuser from v$session t where t.USERNAME='USERNAME' 2. 开始sqltrace ... execute dbms_system.set_... 例: tkprof sqltrace文件.trc a.out 8. 打开a.out

    PL/SQL Developer 9.0.4.1644 绿色中文版_带注册机

    • 使用解释计划工具或 tkprof 工具优化你的 SQL 语句。 • 使用 SQL*Plus 或其他工具在你的数据库中查看或修改其他对象和数据。 这些任务——编辑、编译、纠正、测试、调试、优化和查询——都可以在不离开 PL/...

    ORACLE9i_优化设计与系统调整

    §12.4.1 对所有SQL语句执行EXPLAIN_PLAN 145 §12.4.2 磁盘读和缓冲区获取 146 §12.4.3 判定式崩溃 146 §12.5 使用EXISTS和IN 148 §12.6 分离事务(Discrete Transactions ) 149 §12.7 测试SQL语句性能 151 §...

    PL/SQL Developer 9.0 用户指南

    • 使用解释计划工具或 tkprof 工具优化你的 SQL 语句。 • 使用 SQL*Plus 或其他工具在你的数据库中查看或修改其他对象和数据。这些任务——编辑、编译、纠正、测试、调试、优化和查询——都可以在不离开 PL/SQL ...

    PL_SQL_Developer用户手册

     使用解释计划工具或 tkprof 工具优化你的 SQL 语句。  使用 SQL*Plus 或其他工具在你的数据库中查看或修改其他对象和数据。 这些任务——编辑、编译、纠正、测试、调试、优化和查询——都可以在不离开 PL/SQL ...

    PL/SQL Developer 7.0用户指南

    1. 介绍 PL/SQL Developer 是一个为 Oracle 数据库开发存储程序单元的集成开发环境...• 使用解释计划工具或 tkprof 工具优化你的 SQL 语句。 • 使用 SQL*Plus 或另外的工具在你的数据库里查看或修改其它对象和数据

Global site tag (gtag.js) - Google Analytics