你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle数据库查看执行计划

[日期:2012-05-25] 来源:Linux社区  作者:kerrycode [字体:大 中 小]

TKPROF的帮助信息如下

TKPROF 选项  
选项                                          说明 
TRACEFILE                               跟踪输出文件的名称 
OUTPUTFILE                              已设置格式的文件的名称 
SORT
=option                             语句的排序顺序 
PRINT
=n                                 打印前 n 个语句 
EXPLAIN
=user/password                   以指定的用户名运行 EXPLAIN PLAN 
INSERT
=filename                         生成 INSERT 语句 
SYS
=NO                                  忽略作为用户 sys 运行的递归 SQL 语句 
AGGREGATE
=[Y|N]                         如果指定 AGGREGATE = NO TKPROF 不聚集相同  
                                        SQL 文本的多个用户 
RECORD
=filename                         记录在跟踪文件中发现的语句 
TABLE
=schema.tablename                  将执行计划放入指定的表而不是缺省的PLAN_TABLE  
   
可以在操作系统中键入 tkprof 以获得所有可用选项和输出的列表 
注 排序选项有  
   
排序                                    选项说明 
prscnt execnt fchcnt             调用分析执行提取的次数 
prscpu execpu fchcpu             分析执行提取所占用的 CPU 时间 
prsela exela fchela              分析执行提取所占用的时间 
prsdsk exedsk fchdsk             分析执行提取期间的磁盘读取次数 
prsqry exeqry fchqry             分析执行提取期间用于持续读取的缓冲区数 
prscu execu fchcu                分析执行提取期间用于当前读取的缓冲区数 
prsmis exemis                    分析执行期间库高速缓存未命中的次数 
exerow fchrow                    分析执行期间处理的行数 
userid                           分析游标的用户的用户 ID  
   
TKPROF 统计数据 
Count: 执行调用数 
CPU: CPU 的使用秒数 
Elapsed: 总共用去的时间 
Disk: 物理读取次数 
Query: 持续读取的逻辑读取数 
Current: 当前模式下的逻辑读取数 
Rows: 已处理行数  
TKPROF 统计信息  
统计             含义 
Count     分析或执行语句的次数以及为语句发出的提取调用数 
CPU       每个阶段的处理时间以秒为单位如果在共享池中找到该语句对于分析阶段为
0 
Elapsed   占用时间以秒为单位通常不是非常有用因为其它进程影响占用时间 
Disk      从数据库文件读取的物理数据块如果该数据被缓冲则该统计可能很低 
Query     为持续读取检索的逻辑缓冲区通常用于 SELECT 语句 
Current   在当前模式下检索的逻辑缓冲区通常用于 DML 语句  
Rows      外部语句所处理的行对于 SELECT 语句在提取阶段显示它对于 DML 语句在执行阶段显示它  
   
Query 和Current 的总和为所访问的逻辑缓冲区的总数

执行下面命令:tkprof D:\Oracle\PRODUCT\10.2.0\DB_1\RDBMS\TRACE/wgods_ora_3940.trc h:\out.txtoutputfile explain=etl/etl

clip_image012

执行上面命令后,可以查看生成的文本文件

TKPROF: Release 10.2.0.1.0 - Production on 星期三 5月 23 16:56:41 2012

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

Trace file: D:\ORACLE\PRODUCT\10.2.0\DB_1\RDBMS\TRACE/wgods_ora_3940.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 SESSION 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.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: 0
Misses in library cache during execute: 1
Optimizer mode: CHOOSE
Parsing user id: 89  (ETL)
********************************************************************************

begin :id := sys.dbms_transaction.local_transaction_id; end;


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           2
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          0          0           2

Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: 89  (ETL)
********************************************************************************

SELECT * 
FROM
 SCOTT.EMP


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      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          7          0          14
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          7          0          14

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 89  (ETL)

Rows     Execution Plan
-------  ---------------------------------------------------
      0  SELECT STATEMENT   MODE: CHOOSE
      0   TABLE ACCESS   MODE: ANALYZED (FULL) OF 'EMP' (TABLE)

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

ALTER SESSION SET SQL_TRACE = FALSE


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        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.00       0.00          0          0          0           0

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 89  (ETL)



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

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        5      0.00       0.00          0          0          0           0
Execute      5      0.00       0.00          0          0          0           2
Fetch        1      0.00       0.00          0          7          0          14
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total       11      0.00       0.00          0          7          0          16

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


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        0      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        0      0.00       0.00          0          0          0           0

Misses in library cache during parse: 0

    6  user  SQL statements in session.
    0  internal SQL statements in session.
    6  SQL statements in session.
    1  statement EXPLAINed in this session.
********************************************************************************
Trace file: D:\ORACLE\PRODUCT\10.2.0\DB_1\RDBMS\TRACE/wgods_ora_3940.trc
Trace file compatibility: 10.01.00
Sort options: default

       1  session in tracefile.
       6  user  SQL statements in trace file.
       0  internal SQL statements in trace file.
       6  SQL statements in trace file.
       4  unique SQL statements in trace file.
       1  SQL statements EXPLAINed using schema:
           ETL.prof$plan_table
             Default table was used.
             Table was created.
             Table was dropped.
      58  lines in trace file.
       0  elapsed seconds in trace file.

 

4.3跟踪其它用户的进程,在很多时候我们需要跟踪其它用户的进程,而不是当前用户,可以通过ORACLE提供的系统包

DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION来完成。

例如:

 

SELECT SID, SERIAL#, USERNAME FROM V$SESSION WHERE USERNAME = 'ETL'

EXEC DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION(61,76,TRUE);

EXEC DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION(61,76,FALSE);
linux
相关资讯       oracle数据库教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款