tkprof view trace file

For specific operations, enable trace file tracking.
Enable session level (for specific operations, try to use this level)
SQL> alter session set sql_trace=true;
SQL> alter session set events '10046 trace name context forever,level 12';
SQL> exec sys.dbms_system.set_sql_trace_in_session(10 , 39196 , true);
turn on instance level (tracking of instances)
SQL> alter system set sql_trace=true;
turn off trace trace
session level
SQL> alter session set sql_trace=false;
SQL> alter session set events '10046 trace name context off';
SQL> exec sys.dbms_system.set_sql_trace_in_session(10 , 39196 , false);
instance level
SQL> alter system set sql_trace=false;


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) The usage of several important parameters explains the
sys parameter. If not specified, the default value is yes. The meaning of this parameter is whether the output file contains SQL statements run by the SYS user. This parameter is quite useful. When we execute sql statements, many recursive statements are often executed in the background. For example, if you enter SELECT * FROM TEST; if this statement is hard parsed, it will generate a lot of recursive SQL, recursive To query the statistics of the table, the statistics of the columns, the statistics of the index, etc. Of course, the recursion is not only these. These recursive SQLs are run by the SYS user. If you do not want to see these recursive SQLs, then add the parameter sys=
no.record parameter, which specifies a file under a path, which is used to generate All non-recursive SQL found in trace files. For example, if you execute three statements in SQLPLUS, select * from a;select * from b;select * from c;, then if you specify this parameter such as: record=c:\test.log, then you format it with tkprof After tracing the file, the three SQLs will be recorded in this test.log. This feature is very useful sometimes, because the trace files are often large and it will be more difficult to find. We can first get a general understanding of the non-recursive SQL in the trace files by specifying this parameter. And this feature also helps us to repeat the SQL statement (bind variables can not).
The aggregate parameter, which specifies whether tkprof will aggregate the sql with the same text content, for example, if you execute select * from a ten times, if you specify this parameter as no (the default), then there will be ten output files like this The execution information of the statement. If you specify yes, then tkprof will summarize and display the execution information of these ten times. How to specify this parameter depends on your needs. Personally, I think it is still a useful parameter.
sort parameter, this parameter is a frequently used parameter. It is used to specify the order of the SQL statements in the tkprof output file. The default is to order in the order of execution. We can specify that it is ordered in other ways, such as disk reading. number, CPU time, etc. The most commonly used method of this parameter is: sort=prsela, exeela, fchela, in fact, the three values ​​add up to the response time, that is, they are sorted according to the response time. Don't misunderstand here, tkprof will sort according to the sum of the three values ​​of prsela, exeela, and fchela, instead of sorting them one by one like SQL statements.
The print parameter, which is often used with the sort parameter, is used to specify the number of sql statements output by tkprof. It is better to use these two parameters together. For example, if you want to know the top ten SQLs in response time in a trace file, then you can use sort=prsela,exeela,fchela print=10 together.
explain parameter, the meaning of this parameter is to provide an execution plan for each SQL. The method used is explain=username/password. In fact, the principle is very simple, that is, log in to the database through the user name and password you specify, and then execute the following explain plan for sql for each sql, output it to plan_table, and finally add it to the output file inside. Note that since the explain plan for command requires that the user who performs the operation has execute permission on the objects contained in the SQL statement, if a view is included, it must also have execute permission on the underlying table on which the view is based, otherwise the execution plan cannot be generated. Note that after adding this parameter, the execution of tkprof will be slower.
The wait parameter specifies that the output file contains or does not contain wait events. The default is to contain them. Generally take the default value.
These are the most commonly used ones. I won't introduce the others. Usually, these are basically enough.

trace文件样例
TKPROF: Release 10.2.0.1.0 - Production on Sun Apr 22 11:00:58 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Trace file: orcl_ora_4299.trc
Sort options: fchela


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


The following statements encountered a error during parse:
BEGIN :a = 99; END;

Error encountered: ORA-06550

alter session set sql_trace=off
Error encountered: ORA-00922


error connecting to database using: system/manager
ORA-01017: invalid username/password; logon denied
EXPLAIN PLAN option disabled.


select count(*)
from
t where id = :a
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 2 0.03 0.04 99 106 0 1


total 4 0.04 0.05 99 106 0 1
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 55
Rows Row Source Operation


  1  SORT AGGREGATE (cr=106 pr=99 pw=0 time=46182 us)

50422 INDEX FAST FULL SCAN T_IDX (cr=106 pr=99 pw=0 time=4489223 us)(object id 52998)


OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows


Parse 10 0.00 0.01 0 0 0 0
Execute 12 0.01 0.03 0 0 0 3
Fetch 10 0.07 0.08 99 316 0 5


total 32 0.09 0.13 99 316 0 8
Misses in library cache during parse: 8
Misses in library cache during execute: 8
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows


Parse 47 0.03 0.05 0 0 0 0
Execute 210 0.05 0.07 0 0 0 0
Fetch 328 0.06 0.04 0 852 0 976


total 585 0.15 0.16 0 852 0 976
Misses in library cache during parse: 22
Misses in library cache during execute: 22
12 user SQL statements in session.
210 internal SQL statements in session.
222 SQL statements in session.
0 statements EXPLAINed in this session.


Trace file: orcl_ora_4299.trc
Trace file compatibility: 10.01.00
Sort options: fchela
1 session in tracefile.
12 user SQL statements in trace file.
210 internal SQL statements in trace file.
222 SQL statements in trace file.
30 unique SQL statements in trace file.
2131 lines in trace file.
130 elapsed seconds in trace file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326045503&siteId=291194637