接上一笔记[terry笔记]Oracle会话追踪(一):SQL_TRACE&EVENT 10046
http://www.cnblogs.com/kkterry/p/3279282.html
在系统下执行tkprof,效果是把trace文件转换成可供人类阅读的格式
(个人感觉不是很爽,trace文件输出的时候直接弄个好格式不就得了)
语法:
tkprof tracefile output_file
explain=username/passwd ##对trace文件中的sql语句产生执行计划,会在这个用户下产生plan_table,并在tkprof结束时删除。
sys=yes|no ##选no,用来屏蔽oracle内部递归sql
waits=yes|no ##选yes,记录等待事件概要
aggregate=yes|no ##选yes,oracle会组合相同sql文本的多个用户
record=filename ##会生成一个保存所有sql语句的文件
print=number ##只显示前N条语句,一般和sort一起用
insert=filename ##生成一个脚本,记录所追踪的sql语句的insert
sort=parameters ##输出的内容按照某项排序:按照实际执行时间排序fchela,物理读排序fchdsk
例子:
tkprof ora11g_ora_11111.trc scott.txt explain=scott/tiger sys=no waits=yes sort=fchela
tkprof的输出(分上下两部分):
TKPROF: Release 11.2.0.3. - Development on Sat Aug :: Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Trace file: ora11g_ora_5829.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
******************************************************************************** SQL ID: 9kcpyjv574vjc Plan Hash: select * from t1 where owner='SYSTEM'
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0.00 0.00
Execute 0.00 0.00
Fetch 0.00 0.01
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 0.00 0.01 Misses in library cache during parse:
Optimizer mode: ALL_ROWS
Parsing user id: (U1)
Number of plan statistics captured: Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
TABLE ACCESS FULL T1 (cr= pr= pw= time= us cost= size= card=) Rows Execution Plan
------- ---------------------------------------------------
SELECT STATEMENT MODE: ALL_ROWS
TABLE ACCESS (FULL) OF 'T1' (TABLE)
Trace file: ora11g_ora_5829.trc
Trace file compatibility: 11.1.0.7
Sort options: fchela
session in tracefile.
user SQL statements in trace file. ##这里面共有5个sql
internal SQL statements in trace file. ##1个sql是oracle内部递归
SQL statements in trace file.
unique SQL statements in trace file.
SQL statements EXPLAINed using schema:
U1.prof$plan_table
Default table was used.
Table was created.
Table was dropped.
lines in trace file.
elapsed seconds in trace file.
这里解释下query和current
query就是select语句在内存中检索了多少块
current就是update、delete等语句在内存中修改了多少块
一些指标:
好的情况是以很少的fatch获取更多的rows。
query的parse指的是从数据字典(dictionary cache)中获取多少块。
主要以CPU列和elapsed列来衡量资源的消耗。
要消灭全表扫描。