网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > 数据库技术 > Oracle > PL/SQL > 了解raw trace文件的各项内容  

了解raw trace文件的各项内容

2005-11-05  作者:BitsCN整理  来源:中国网管联盟  点评 投稿 收藏


  今天浏览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结果。 网管网www_bitscn_com
  
  那么为什么还要直接读取trace文件呢?最重要的是tkprof的结果是不包含绑定变量值的,同时也不包括真正的SQL执行顺序,而trace文件中我们则可以看到按照时间排列的parse,binds,executes,fetch等等,这在某西场合下是很有用处的。还有就是,如果你能够直接读取这些让人看得眼晕的trace,是不是会有一种很爽,很大师的感觉:-)
  
  当然如果我们要根据一些标准(比如CPU时长,磁盘读取量等)进行trace中的SQL排序,那么tkprof是我们唯一的选择,可以参看coolyl(丫现在迷恋WOW,已经不理朝政了:-D)的Tkprof工具介绍和分析。
  
  下面是metalink中的这篇文章的大体翻译,大部分名词用英文反而更好,就不强加翻译了,相信大家都看得懂。当然也是比较懒的原因:-)
  
  文本总结了trace结果原始输出文件中的内容。
  
  ----------------------------------------------------------------------------
  APPNAME mod='%s' mh=%lu act='%s' ah=%lu
  ----------------------------------------------------------------------------
  

网管有家bitscn.net


  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'
  statement....
  END OF STMT
  ----------------------------------------------------------------------------
  
  CURSOR: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
网管论坛bbs_bitsCN_com

  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字段值相等。
  statement :The actual SQL statement being parsed.
  
  ----------------------------------------------------------------------------
  PARSE ERROR #%d:len=%ld dep=%d uid=%ld oct=%d lid=%ld tim=%lu err=%d
  statement....
  ----------------------------------------------------------------------------
  
  PARSE ERROR :在Oracle 7.2以上版本中解析的错误会写入trace文件中。

网管u家u.bitsCN.com


  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
  statement :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
中国网管论坛bbs.bitsCN.com

  FETCH :Fetch rows from a cursor. 从游标中得到数据,通常指select返回记录
  UNMAP :如果游标使用了临时表(temporary table), 当游标关闭的时候将会看到UNMAP
  c :CPU time (100th's of a second in Oracle7 ,8 and 9).
  e :Elapsed time (100th's 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
  ---------------------------------------------------------------------------- 网管论坛bbs_bitsCN_com
  
  执行或者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的执行计划.
  CURSOR :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)'

网管网www.bitscn.com


  
  ----------------------------------------------------------------------------
  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
网管有家www.bitscn.net

  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=
TAGs各项   内容   了解   SQL   trace   tim   结果   dep   cr   执行    
 上一篇:oracle数据库的优化-关于rownum操作   下一篇:过程,函数,程序包
相关文章列表
了解raw trace文件的各项内容 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
1.PL/SQL - 嵌套游标 cursor-PLSQL
2.用一个实例讲解Oracle数据库的PL/SQL语句
3.PL/SQL----触发器-PLSQL
4.mysql存储过程写法—动态参数运用-PLSQL
5.PL/SQL Developer导出分区索引脚本-PLSQL
6.PL/SQL collection— table() 函数-PLSQL
7.SQL Server 2005 中的架构与用户-PLSQL
8.Oracle数据库维护常用SQL语句集合(2)-P
9.Oracle数据库维护常用SQL语句集合(3)-P
10.再议SQL Server临时表和表变量-PLSQL
最新推荐文章:
1.与数据库无关的处理放到数据库以外来实现
2.Oracle 10g第2版新特性之SQL和PL/SQL
3.通过PL/SQL访问Web Services
4.菜鸟学oracle - 用PL/SQL画直方图
5.重新编译PLSQL中无效对象或指定对象
6.Oracle高级技巧
7.深入了解Oracle 10g新的多重集运算符
8.在SQL中删除重复记录(多种方法)
9.Oracle:PL/SQL中怎样使用Array
10.数据库手册:速查Oracle函数列表
网管论坛交流:
·大家来开心一下吧---看了会很开心的东西-
·中国人不可不知道的知识
·@@小鹏◎◎小鹏同志与某位女明星亲密接触
·◎◎小鹏◎◎发现不明生物,居然正在交配
·[图文]^^^版主是什么?????
·泡论坛的女人是好女人
·做个“水性杨花”的女人
·献给mm俱乐部的所有mm
·深圳一集团企业电脑基础应用培训教程
·■■■■十一遊玩照■■■■■