1)TKPROF的参数:
不输入任何参数,直接输入tkprof,回车,可以获得一个完整的参数列表.
C:\>tkprof
Usage: tkprof tracefile outputfile [explain= ] [table= ]
[print= ] [insert= ] [sys= ] [sort= ]
table=schema.tablename Use 'schema.tablename' with 'explain=' option.
explain=user/password Connect to ORACLE and issue EXPLAIN PLAN.
print=integer List only the first 'integer' SQL statements.
aggregate=yes|no
insert=filename List SQL statements and data inside INSERT statements.
sys=no TKPROF does not list SQL statements run as user SYS.
record=filename Record non-recursive statements found in the trace file.
waits=yes|no Record summary for any wait events found in the trace file.
sort=option Set of zero or more of the following sort options:
prscnt number of times parse was called
prscpu cpu time parsing
prsela elapsed time parsing
prsdsk number of disk reads during parse
prsqry number of buffers for consistent read during parse
prscu number of buffers for current read during parse
prsmis number of misses in library cache during parse
execnt number of execute was called
execpu cpu time spent executing
exeela elapsed time executing
exedsk number of disk reads during execute
exeqry number of buffers for consistent read during execute
execu number of buffers for current read during execute
exerow number of rows processed during execute
exemis number of library cache misses during execute
fchcnt number of times fetch was called
fchcpu cpu time spent fetching
fchela elapsed time fetching
fchdsk number of disk reads during fetch
fchqry number of buffers for consistent read during fetch
fchcu number of buffers for current read during fetch
fchrow number of rows fetched
userid userid of user that parsed the cursor
2)几个重要参数的用法讲解
·sys参数,如果不指定默认值为yes.这个参数的含义是,输出文件中是否包含以SYS用户运行的sql语句。这个参数还是蛮有用的,我们执行sql语句的时候,后台经常会执行很多递归的语句,比如你输入了SELECT * FROM TEST;如果这个语句是硬解析的话,那么会产生很多递归的SQL,递归的去查询表的统计信息,列的统计信息,索引的统计信息等,当然递归的不止是这些。这些递归的sql都是以SYS用户运行的,如果你不希望看到这些递归SQL,那么就加上这个参数sys=no.
·record参数,它指定的是一个路径下的文件,这个文件用来生成在跟踪文件中找到的所有的非递归SQL。比如你在SQLPLUS里执行了三条语句,select * from a;select * from b;select * from c;,那么如果你指定了这个参数如:record=c:\test.log,那么你用tkprof格式化跟踪文件后,这个test.log里就会记录这三个SQL。这个特性在有些时候还是蛮有用的,因为跟踪文件往往都会比较大,找起来会比较费劲,我们可以通过指定这个参数先大体了解下,跟踪文件里都有哪些非递归SQL。而且这个功能还有助于我们重演SQL语句(绑定变量的不可以)。
·aggregate参数,它指定tkprof是否将同样文本内容的sql聚合处理,比如,你执行了十次select * from a,如果你指定这个参数为no(默认情况),那么产生的输出文件会有十个这样语句的执行信息,如果你指定的是yes,那么tkprof会把这十次的执行信息汇总显示。这个参数怎么指定就看你的需要了,个人觉得还是满有用的一个参数。
·explain参数,这个参数的含义是为每一个SQL提供一个执行计划。使用的方法是explain=用户名/密码,其实原理很简单,就是通过你指定的用户名,密码登陆数据库,然后为每一个sql执行以下explain plan for sql,输出到plan_table里,最后添加到输出文件里。注意,由于explain plan for 命令要求执行操作的用户要对sql语句里包含的对象都有执行权限,如果包含视图,也要对视图基于的基础表有执行权限,否则产生不了执行计划。注意增加了这个参数后,执行tkprof会比较慢。
对会话启动SQL TRACE
alter session set sql_trace=true;
alter session set sql_trace=false;
SYS.DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION=( SID , SERIAL# , TRUE );
SID,SERIAL#可以从V$SESSION视图获得。
ALTER SESSION SET EVENTS
alter session set events '10046 trace name context forever,level<n>';
alter session set events '10046 trace name context off';
alter system set events '10046 trace name context forever,level 1'
alter system set events '10046 trace name context off'
insert=filename List SQL statements and data inside INSERT statements. SQL脚本的一种,用于将跟踪文件的动机信息存储到数据库中
sys=no TKPROF does not list SQL statements run as user SYS. 于启动或禁止将用户SYS所发布的SQL语句列表到输出文件之中,也包括递归SQL(为执行用户的SQL语句,ORACLE还必须执行一些附加语句)语句在内。默认为YES
record=filename Record non-recursive statements found in the trace file. 对于跟踪文件中的所用非递归SQL语句,TKPROF 将以指定的名称来创建某个SQL脚本。用于对跟踪文件中的用户时间进行重放
waits=yes|no Record summary for any wait events found in the trace file.
sort=option Set of zero or more of the following sort options: 在将被跟踪的SQL语句列表输出到跟踪文件之前,先将其按照指定排序选项的降序关系对其进行排序;若指定了多种排序选项,那么根据排序选项所指定值的和的降序关系对其进行排序;若忽略此参数,那么TKPROF将按照使用次序把语句列表到输出文件中
prscnt number of times parse was called 语句解析的数目
prscpu cpu time parsing 语句解析所占用的CPU时间
prsela elapsed time parsing 语句解析所占用的时间(总是大于或等于CPU时间);
prsdsk number of disk reads during parse 语句解析期间,从磁盘进行物理读取的数目
prsqry number of buffers for consistent read during parse 语句解析期间,一致模式块读取(CONSISTENT MODE BLOCK READ)的数目
prscu number of buffers for current read during parse 语句解析期间,当前模式读取(CURRENT MODE BLOCK READ)的数目
prsmis number of misses in library cache during parse 语句解析期间,库缓存失败的数目
execnt number of execute was called 语句执行的数目
execpu cpu time spent executing 语句执行所占用的CPU时间
exeela elapsed time executing 语句执行所占用的时间(总是大于或等于CPU时间)
exedsk number of disk reads during execute 语句执行期间,从磁盘进行物理读取的数目
exeqry number of buffers for consistent read during execute 语句执行期间,一致模式块读取(CONSISTENT MODE BLOCK READ)的数目
execu number of buffers for current read during execute 语句执行期间,当前模式读取(CURRENT MODE BLOCK READ)的数目
exerow number of rows processed during execute 语句执行期间,所处理的语句行数
exemis number of library cache misses during execute 语句执行期间,库缓存失败的数目
fchcnt number of times fetch was called 取数据的数目
fchcpu cpu time spent fetching 取数据所占用的CPU时间
fchela elapsed time fetching 取数据所占用的时间(总是大于或等于CPU时间)
fchdsk number of disk reads during fetch 取数据期间,从磁盘进行物理读取的数目
fchqry number of buffers for consistent read during fetch 取数据期间,一致模式块读取(CONSISTENT MODE BLOCK READ)的数目
fchcu number of buffers for current read during fetch 取数据期间,当前模式读取(CURRENT MODE BLOCK READ)的数目
fchrow number of rows fetched 所获取的行数
userid userid of user that parsed the cursor
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 0.00 0.00