Username: Password:

了解raw trace文档的各项内容-数据库专栏,SQL Server
来源:作者: 发布时间:2007-12-25 13:43:31


今天浏览metalink,看到这篇interpreting raw sql_trace,比较老的一篇文章了,但是确实很有用,所以决定大略翻译一下吧。

我们知道有几种方法能够得到一个sql语句执行时后台的trace文档,一个是用sql_trace,一个是用dbms_support包或dbms_system包,更有一种就是直接使用10046 event。

使用10046 event的方法大致如下:

alter session set events 10046 trace name context forever, level 12;


your sql statement...

alter session set events 10046 trace name context off;

其中的level有1,4,8,12几个选项,其中1相当于配置sql_trace=true之后的结果,4包括1的结果和绑定变量的实际值,8包括1的结果和等待事件的情况,12则同时包含1的结果,绑定变量的实际值和等待事件情况,所以能够说level 12是最为周详的trace了。

同时我们也知道,对于trace结果,oracle提供了tkprof实用程式用来格式化trace文档,提供一份更容易读懂的trace结果。

那么为什么还要直接读取trace文档呢?最重要的是tkprof的结果是不包含绑定变量值的,同时也不包括真正的sql执行顺序,而trace文档中我们则能够看到按照时间排列的parse,binds,executes,fetch等等,这在某西场合下是很有用处的。更有就是,假如您能够直接读取这些让人看得眼晕的trace,是不是会有一种很爽,很大师的感觉:-)

当然假如我们要根据一些标准(比如cpu时长,磁盘读取量等)进行trace中的sql排序,那么tkprof是我们唯一的选择,能够参看coolyl的tkprof工具介绍和分析。

 

下面是metalink中的这篇文章的大体翻译,大部分名词用英文反而更好,就不强加翻译了,相信大家都看得懂。当然也是比较懒的原因:-)

 

文本总结了trace结果原始输出文档中的内容。

 

----------------------------------------------------------------------------

appname mod=%s mh=%lu act=%s ah=%lu

----------------------------------------------------------------------------

 

appname:application name setting。在oracle 7.2和以上版本中出现。这个名称能够由dbms_application_info包来设定。

mod:module name

mh:module hash value

act:action

ah:action hash value

 

比如:appname mod=sql*plus mh=3669949024 act= ah=4029777240

 

----------------------------------------------------------------------------

parsing in cursor # len=x dep=x uid=x oct=x lid=x tim=x hv=x ad=x



end of stmt

----------------------------------------------------------------------------

 

:cursor number

len :length of sql statement,sql语句的长度

dep :recursive depth of the cursor,当前sql语句的递规深度,假如为0则表示是用户提交的sql,为1则是由于用户sql而导致oracle后台自己执行的sql,为2则是由1级sql继续诱发的下一级sql。

uid :schema user id of parsing user

oct :oracle command type.

lid :privilege user id.

tim :timestamp。在oracle9i之前单位是1/100秒,9i则是1/1,000,000秒。利用这个值能够计算一个sql执行了到底多长时间。这个值就是当前行被写入trace文档时数据库v$timer视图的值。

hv :hash id.

ad :sqltext address,sqltext的地址,跟v$sqlarea和v$sqltext视图中的address字段值相等。

:the actual sql statement being parsed.

 

----------------------------------------------------------------------------

parse error #%d:len=%ld dep=%d uid=%ld oct=%d lid=%ld tim=%lu err=%d

...

----------------------------------------------------------------------------

 

parse error :在oracle 7.2以上版本中解析的错误会写入trace文档中。

len :length of sql statement.

dep :recursive depth of the statement

uid :user id.

oct :oracle command type (if known).

lid :privilege user id.

tim :timestamp.

err :oracle error code (e.g. ora-xxxxx) reported

:the sql statement that errored.

 

----------------------------------------------------------------------------

parse #:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=0

exec #:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=0

fetch #:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=0

unmap #:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=0

----------------------------------------------------------------------------

 

parse :parse a statement. 解析一个sql

exec :execute a pre-parsed statement. 执行已解析完毕的sql

fetch :fetch rows from a cursor. 从游标中得到数据,通常指select返回记录

unmap :假如游标使用了临时表(temporary table), 当游标关闭的时候将会看到unmap

c :cpu time (100ths of a second in oracle7 ,8 and 9).

e :elapsed time (100ths of a second oracle7, 8. microseconds in oracle 9 onwards).

p :number of physical reads.

cr :number of buffers retrieved for cr reads.

cu :number of buffers retrieved in current mode.

mis :cursor missed in the cache.

r :number of rows processed.

dep :recursive call depth (0 = user sql, >0 = recursive).

og :optimizer goal: 1=all_rows, 2=first_rows, 3=rule, 4=choose

tim :timestamp (large number in 100ths of a second).

 

比如:fetch #2:c=0,e=106,p=0,cr=3,cu=0,mis=0,r=1,dep=1,og=4,tim=6005498548671

 

----------------------------------------------------------------------------

error #%d:err=%d tim=%lu

----------------------------------------------------------------------------

 

执行或fetch之后出现的sql error

err :oracle error code (e.g. ora-xxxxx) at the top of the stack.

tim :timestamp.

 

----------------------------------------------------------------------------

stat # id=n cnt=0 [pid=0 pos=0 obj=0 op=sort aggregate ]

----------------------------------------------------------------------------

 

的执行计划.

:cursor which the statistics apply to.

id :line of the explain plan which the row count applies to (从1开始).

cnt :number of rows for this row source.

pid :parent id of this row source.

pos :position in explain plan.

obj :object id of row source (if this is a base object).

op : the row source access operation.

 

比如:

stat #2 id=2 cnt=0 pid=1 pos=1 obj=510 op=table access by index rowid object_usage (cr=2 r=0 w=0 time=83 us)

stat #2 id=3 cnt=1 pid=2 pos=1 obj=511 op=index range scan i_stats_obj# (cr=1 r=0 w=0 time=43 us)

 

----------------------------------------------------------------------------

xctend rlbk=%d rd_only=%d

----------------------------------------------------------------------------

 

xctend是事务结束的标志.

rlbk :1 if a rollback was performed, 0 if no rollback (commit).

rd_only :1 if transaction was read only, 0 if changes occurred.

 

----------------------------------------------------------------------------

binds #%d:

bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=24 offset=0

bfp=02fedb44 bln=22 avl=00 flg=05

value=10

----------------------------------------------------------------------------

 

bind :variables bound to a cursor.

bind n :the bind position being bound.

dty :data type.

mxl :maximum length of the bind variable (private max len in paren).

mal :array length.

scl :scale.

pre :precision.

oacflg :special flag indicating bind options

oacflg2 :continuation of oacflg

size :amount of memory to be allocated for this chunk

offset :offset into this chunk for this bind buffer

bfp :bind address.

bln :bind buffer length.

avl :actual value length (array length too).

flg :special flag indicating bind status

value :the actual value of the bind variable.

 

比如:

binds #4:

 bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0

   bfp=ffffffff7ce64ee0 bln=22 avl=01 flg=05

   value=0

 bind 1: dty=1 mxl=32(11) mal=00 scl=00 pre=00 oacflg=18 oacfl2=1 size=32 offset=0

   bfp=ffffffff7ce6b128 bln=32 avl=11 flg=05

   value="tabcompart$"

 bind 2: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0

   bfp=ffffffff7ce6bae8 bln=24 avl=02 flg=05

   value=1

 

----------------------------------------------------------------------------

wait #: nam="" ela=0 p1=0 p2=0 p3=0

----------------------------------------------------------------------------

 

wait :an event that we waited for.

nam :what was being waited for.

ela :elapsed time for the operation.

p1 :p1 for the given wait event.

p2 :p2 for the given wait event.

p3 :p3 for the given wait event.

 

比如 (full table scan):

wait #1: nam="db file scattered read" ela= 5 p1=4 p2=1435 p3=25

在游标1上经历了"db file scattered read"等待事件,一共等了0.05秒,在读取file 4,从1435 block开始,读了25个block

 

比如 (index scan):

wait #1: nam="db file sequential read" ela= 4 p1=4 p2=1224 p3=1

在游标1上经历了"db file sequential read"等待事件,一共等了0.04秒,在读取file 4,block 1224,读取了这一个block

 

对于每一个等待事件的含义和p1,p2,p3表示的意思,能够参考oracle database reference文档的oracle wait events章节。

 

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅