首页 > 数据库技术 > 详细

如何使用SQL_TRACE和10046事件

时间:2015-05-26 02:20:58      阅读:330      评论:0      收藏:0      [点我收藏+]

Eygle大师的微信讲堂昨天开课,第一堂课和大家分享了一些学习Oracle的基本方法,其中提到了使用SQL_TRACE10046事件。SQL_TRACEOracle提供的用于进行SQL跟踪的手段,是强有力的辅助诊断工具。在日常的数据库问题诊断和解决中,SQL_TRACE是非常常用的方法。

      对于这个工具,我很早就听过,但是从来就没用过,“纸上得来终觉浅,绝知此事要躬行”,操练起来。

1.环境准备

      我们在Oracle11g中进行测试。

点击(此处)折叠或打开

  1. SQL>
  2. SQL> select * from v$version;

  3. BANNER
  4. --------------------------------------------------------------------------------
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
  6. PL/SQL Release 11.2.0.3.0 - Production
  7. CORE 11.2.0.3.0 Production
  8. TNS for Linux: Version 11.2.0.3.0 - Production
  9. NLSRTL Version 11.2.0.3.0 - Production

  10. SQL>

2.启用SQL_TRACE

      Oracle中初始化设置中SQL_TRACE默认是关闭的,它可以作为初始化参数在全局启用,也可以通过命令行方式在具体session启用。

1. 在全局启用

在参数文件(pfile/spfile)中指定:

SQL_TRACE =true

在全局启用SQL_TRACE会导致所有进程的活动被跟踪,包括后台进程及所有用户进程,这通常会导致比较严重的性能问题,所以在生产环境中要谨慎使用,这个参数在10g之后是动态参数,可以随时调整,在某些诊断中非常有效。

提示: 通过在全局启用SQL_TRACE,我们可以跟踪到所有后台进程的活动,很多在文档中的抽象说明,通过跟踪文件的实时变化,我们可以清晰的看到各个进程之间的紧密协调。

2. 在当前session级设置

      大多数时候我们使用SQL_TRACE跟踪当前进程.通过跟踪当前进程可以发现当前操作的后台数据库递归活动(这在研究数据库新特性时尤其有效),研究SQL执行,发现后台错误等。

     我在测试中启用session级别的SQL_TRACE,如下所示。

点击(此处)折叠或打开

  1. SQL>
  2. SQL> show parameter SQL_TRACE

  3. NAME TYPE VALUE
  4. ------------------------------------ ----------- ------------------------------
  5. SQL_TRACE boolean FALSE
  6. SQL>
  7. SQL> alter session set SQL_TRACE=true;

  8. Session altered.

  9. SQL>
  10. SQL> show parameter SQL_TRACE

  11. NAME TYPE VALUE
  12. ------------------------------------ ----------- ------------------------------
  13. SQL_TRACE boolean TRUE
  14. SQL>

3.连接soctt用户,执行查询语句

     登陆scott用户,执行两条简单的查询语句。

点击(此处)折叠或打开

  1. [oracle@hoegh admin]$ sqlplus scott/tiger

  2. SQL*Plus: Release 11.2.0.3.0 Production on Wed May 27 09:59:48 2015

  3. Copyright (c) 1982, 2011, Oracle. All rights reserved.


  4. Connected to:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options

  7. SQL> select * from cat;

  8. TABLE_NAME TABLE_TYPE
  9. ------------------------------ -----------
  10. BONUS TABLE
  11. DEPT TABLE
  12. EMP TABLE
  13. SALGRADE TABLE

  14. SQL> select * from dept;

  15.     DEPTNO DNAME LOC
  16. ---------- -------------- -------------
  17.         10 ACCOUNTING NEW YORK
  18.         20 RESEARCH DALLAS
  19.         30 SALES CHICAGO
  20.         40 OPERATIONS BOSTON

4.生成trace文件

plustrace角色

      和Oracle10g一样,11g中plustrace角色默认也是disabled的。如果使用非授权用户打开Oracle trace功能会得到以下的错误。

点击(此处)折叠或打开

  1. SQL>
  2. SQL> show user
  3. USER is \"SCOTT\"
  4. SQL>
  5. SQL> set autotrace on
  6. SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
  7. SP2-0611: Error enabling STATISTICS report
  8. SQL>
     
这时需要执行$ORACLE_HOME/sqlplus/admin/plustrce.sql脚本,手工创建plustrace角色,在此不做演示。因为我们更多的时候是需要跟踪其他用户的进程,而很多这样的用户可能没有被授予或者不允许授予plustrace角色。这时可以使用DBMS_SYSTEM包来实现对进程的跟踪,这儿需要提供用户进程的sid和serial#。

10046事件

     在这儿就不得不提到10046事件,10046事件是Oracle提供的内部事件,是对SQL_TRACE的增强。

10046事件可以设置以下四个级别:

1 - 启用标准的SQL_TRACE功能,等价于SQL_TRACE

4 - Level 1 加上绑定值(bind values)

8 - Level 1 + 等待事件跟踪

12 - Level 1 + Level 4 + Level 8

      和SQL_TRACE类似,10046事件可以在全局设置,也可以在session级设置。

生成trace文件

     首先,我们通过查询v$session视图获取scott用户进程的sid和serial#;
     然后执行dbms_system.set_ev
过程来实现对进程的跟踪。

点击(此处)折叠或打开

  1. SQL>
  2. SQL> select sid,serial#,username from v$session where username=\‘SCOTT\‘;

  3.        SID SERIAL# USERNAME
  4. ---------- ---------- ------------------------------
  5.         21 2615 SCOTT

  6. SQL>
  7. SQL> exec dbms_system.set_ev(21,2615,10046,12,\‘SCOTT\‘);

  8. PL/SQL procedure successfully completed.

  9. SQL>

5.查看trace文件

存放目录

      在11g中trace文件的存放目录有了变化,其中,11gR1 或 11gR1 以上版本可以通过查询diagnostic_dest参数获得;而11gR1以前版本则是通过user_dump_dest参数来指定。

点击(此处)折叠或打开

  1. SQL> show parameter diagnostic_dest

  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. diagnostic_dest string /u01/app/oracle
  5. SQL>
     
在测试数据库中,trace文件的具体路径为:/u01/app/oracle/diag/rdbms/hoegh/HOEGH/trace/

查看trace文件

      tracefile 命名规则 :<ORACLE_SID>_ora_<pid>.trc,其中pid为相应session所对应的OS PID。根据生成时间在/u01/app/oracle/diag/rdbms/hoegh/HOEGH/trace目录下找到了trace文件HOEGH_ora_16427.trc。我们通过more命令查看文件内容,由于内容较多,只截取了开始部分内容如下。

点击(此处)折叠或打开

  1. [oracle@hoegh trace]$ more HOEGH_ora_16427.trc
  2. Trace file /u01/app/oracle/diag/rdbms/hoegh/HOEGH/trace/HOEGH_ora_16427.trc
  3. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
  4. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  5. ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
  6. System name: Linux
  7. Node name: hoegh.example.com
  8. Release: 2.6.18-164.el5PAE
  9. Version: #1 SMP Thu Sep 3 02:28:20 EDT 2009
  10. Machine: i686
  11. VM name: VMWare Version: 6
  12. Instance name: HOEGH
  13. Redo thread mounted by this instance: 1
  14. Oracle process number: 23
  15. Unix process pid: 16427, image: oracle@hoegh.example.com (TNS V1-V3)


  16. *** 2015-05-27 09:56:36.240
  17. *** SESSION ID:(142.1705) 2015-05-27 09:56:36.240
  18. *** CLIENT ID:() 2015-05-27 09:56:36.240
  19. *** SERVICE NAME:(SYS$USERS) 2015-05-27 09:56:36.240
  20. *** MODULE NAME:(sqlplus@hoegh.example.com (TNS V1-V3)) 2015-05-27 09:56:36.2
  21. 40
  22. *** ACTION NAME:() 2015-05-27 09:56:36.240
     
由于trace文件的可读性差,我们使用tkprof对trace文件进行格式化,以下是格式化后的信息内容,在这儿也只截取了开始部门,完整的内容贴到文档的最后供大家参考。

格式化trace文件


点击(此处)折叠或打开

  1. [oracle@hoegh trace]$ tkprof HOEGH_ora_16427.trc 10046.txt

  2. TKPROF: Release 11.2.0.3.0 - Development on Wed May 27 11:20:36 2015

  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.


  4. [oracle@hoegh trace]$

查看格式化后的trace报告


点击(此处)折叠或打开

  1. [oracle@hoegh trace]$ more 10046.txt

  2. TKPROF: Release 11.2.0.3.0 - Development on Wed May 27 11:20:36 2015

  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.


  4. [oracle@ hoegh trace]$



  5. TKPROF: Release 11.2.0.3.0 - Development on Wed May 27 10:06:10 2015

  6. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

  7. Trace file: HOEGH_ora_16427.trc
  8. Sort options: default

  9. ********************************************************************************
  10. count = number of times OCI procedure was executed
  11. cpu = cpu time in seconds executing
  12. elapsed = elapsed time in seconds executing
  13. disk = number of physical reads of buffers from disk
  14. query = number of buffers gotten for consistent read
  15. current = number of buffers gotten in current mode (usually for update)
  16. rows = number of rows processed by the fetch or execute call
  17. ********************************************************************************

  18. SQL ID: 4tk6t8tfsfqbf Plan Hash: 0

  19. alter session set sql_trace=true


  20. call count cpu elapsed disk query current rows
  21. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  22. Parse 0 0.00 0.00 0 0 0 0
  23. Execute 1 0.00 0.00 0 0 0 0
  24. Fetch 0 0.00 0.00 0 0 0 0
  25. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  26. total 1 0.00 0.00 0 0 0 0
      以上内容实现了一个应用sql_trace的简单案例,trace文件的信息量较大,我将会在下一篇文章中和大家分享。  

大师论点

     Eygle在课堂上提到他在面试时经常问的一个问题,“在什么技术上你做过深入思考得到了自己的观点”,绝大多数人的回答都是NO。
     Eygle提倡由点及面、由浅入深的学习方法,确实,不深入是不可能有收获的。
     
     期待下一次eygle在微信讲堂的精彩分享。

hoegh
15.05.22
-- The End --

附完整trace报告            


点击(此处)折叠或打开

  1. TKPROF: Release 11.2.0.3.0 - Development on Wed May 27 11:20:36 2015

  2. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.


  3. [oracle@ hoegh trace]$



  4. TKPROF: Release 11.2.0.3.0 - Development on Wed May 27 10:06:10 2015

  5. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

  6. Trace file: HOEGH_ora_16427.trc
  7. Sort options: default

  8. ********************************************************************************
  9. count = number of times OCI procedure was executed
  10. cpu = cpu time in seconds executing
  11. elapsed = elapsed time in seconds executing
  12. disk = number of physical reads of buffers from disk
  13. query = number of buffers gotten for consistent read
  14. current = number of buffers gotten in current mode (usually for update)
  15. rows = number of rows processed by the fetch or execute call
  16. ********************************************************************************

  17. SQL ID: 4tk6t8tfsfqbf Plan Hash: 0

  18. alter session set sql_trace=true


  19. call count cpu elapsed disk query current rows
  20. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  21. Parse 0 0.00 0.00 0 0 0 0
  22. Execute 1 0.00 0.00 0 0 0 0
  23. Fetch 0 0.00 0.00 0 0 0 0
  24. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  25. total 1 0.00 0.00 0 0 0 0

  26. Misses in library cache during parse: 0
  27. Misses in library cache during execute: 1
  28. Optimizer mode: ALL_ROWS
  29. Parsing user id: SYS
  30. ********************************************************************************

  31. SQL ID: 7cfz5wy9caaf4 Plan Hash: 4015672053

  32. SELECT NAME NAME_COL_PLUS_SHOW_PARAM,DECODE(TYPE,1,\‘boolean\‘,2,\‘string\‘,3,
  33.   \‘integer\‘,4,\‘file\‘,5,\‘number\‘, 6,\‘big integer\‘, \‘unknown\‘) TYPE,
  34.   DISPLAY_VALUE VALUE_COL_PLUS_SHOW_PARAM
  35. FROM
  36.  V$PARAMETER WHERE UPPER(NAME) LIKE UPPER(:NMBIND_SHOW_OBJ) ORDER BY
  37.   NAME_COL_PLUS_SHOW_PARAM,ROWNUM


  38. call count cpu elapsed disk query current rows
  39. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  40. Parse 1 0.00 0.00 0 0 0 0
  41. Execute 1 0.00 0.00 0 0 0 0
  42. Fetch 2 0.00 0.00 0 0 0 1
  43. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  44. total 4 0.01 0.01 0 0 0 1

  45. Misses in library cache during parse: 1
  46. Misses in library cache during execute: 1
  47. Optimizer mode: ALL_ROWS
  48. Parsing user id: SYS
  49. Number of plan statistics captured: 1

  50. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  51. ---------- ---------- ---------- ---------------------------------------------------
  52.          1 1 1 SORT ORDER BY (cr=0 pr=0 pw=0 time=9094 us cost=2 size=2128 card=1)
  53.          1 1 1 COUNT (cr=0 pr=0 pw=0 time=8984 us)
  54.          1 1 1 HASH JOIN (cr=0 pr=0 pw=0 time=8979 us cost=1 size=2128 card=1)
  55.          1 1 1 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=6028 us cost=0 size=94 card=1)
  56.       2752 2752 2752 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=3134 us cost=0 size=203400 card=100)

  57. ********************************************************************************

  58. SQL ID: asvzxj61dc5vs Plan Hash: 3028786551

  59. select timestamp, flags
  60. from
  61.  fixed_obj$ where obj#=:1


  62. call count cpu elapsed disk query current rows
  63. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  64. Parse 1 0.00 0.00 0 0 0 0
  65. Execute 1 0.00 0.00 0 0 0 0
  66. Fetch 1 0.00 0.00 0 2 0 0
  67. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  68. total 3 0.00 0.00 0 2 0 0

  69. Misses in library cache during parse: 1
  70. Misses in library cache during execute: 1
  71. Optimizer mode: CHOOSE
  72. Parsing user id: SYS (recursive depth: 1)
  73. Number of plan statistics captured: 1

  74. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  75. ---------- ---------- ---------- ---------------------------------------------------
  76.          0 0 0 TABLE ACCESS BY INDEX ROWID FIXED_OBJ$ (cr=2 pr=0 pw=0 time=15 us cost=2 size=17 card=1)
  77.          0 0 0 INDEX UNIQUE SCAN I_FIXED_OBJ$_OBJ# (cr=2 pr=0 pw=0 time=10 us cost=1 size=0 card=1)(object id 102)

  78. ********************************************************************************

  79. SQL ID: 96g93hntrzjtr Plan Hash: 2239883476

  80. select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#,
  81.   sample_size, minimum, maximum, distcnt, lowval, hival, density, col#,
  82.   spare1, spare2, avgcln
  83. from
  84.  hist_head$ where obj#=:1 and intcol#=:2


  85. call count cpu elapsed disk query current rows
  86. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  87. Parse 1 0.00 0.00 0 0 0 0
  88. Execute 20 0.00 0.00 0 0 0 0
  89. Fetch 20 0.00 0.00 0 58 0 18
  90. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  91. total 41 0.00 0.00 0 58 0 18

  92. Misses in library cache during parse: 1
  93. Misses in library cache during execute: 1
  94. Optimizer mode: RULE
  95. Parsing user id: SYS (recursive depth: 2)
  96. Number of plan statistics captured: 1

  97. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  98. ---------- ---------- ---------- ---------------------------------------------------
  99.          1 1 1 TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=3 pr=0 pw=0 time=206 us)
  100.          1 1 1 INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=159 us)(object id 427)

  101. ********************************************************************************

  102. SQL ID: db78fxqxwxt7r Plan Hash: 3312420081

  103. select /*+ rule */ bucket, endpoint, col#, epvalue
  104. from
  105.  histgrm$ where obj#=:1 and intcol#=:2 and row#=:3 order by bucket


  106. call count cpu elapsed disk query current rows
  107. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  108. Parse 1 0.00 0.00 0 0 0 0
  109. Execute 2 0.00 0.00 0 0 0 0
  110. Fetch 2 0.00 0.00 0 6 0 3
  111. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  112. total 5 0.00 0.00 0 6 0 3

  113. Misses in library cache during parse: 1
  114. Misses in library cache during execute: 1
  115. Optimizer mode: RULE
  116. Parsing user id: SYS (recursive depth: 2)
  117. Number of plan statistics captured: 1

  118. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  119. ---------- ---------- ---------- ---------------------------------------------------
  120.          1 1 1 SORT ORDER BY (cr=3 pr=0 pw=0 time=182 us cost=0 size=0 card=0)
  121.          1 1 1 TABLE ACCESS CLUSTER HISTGRM$ (cr=3 pr=0 pw=0 time=150 us)
  122.          1 1 1 INDEX UNIQUE SCAN I_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=102 us)(object id 422)

  123. ********************************************************************************

  124. SQL ID: gcnf7vvsyq6w3 Plan Hash: 0

  125. select SADDR , SID , SERIAL# , AUDSID , PADDR , USER# , USERNAME , COMMAND ,
  126.   OWNERID, TADDR , LOCKWAIT , STATUS , SERVER , SCHEMA# , SCHEMANAME ,OSUSER ,
  127.    PROCESS , MACHINE , PORT , TERMINAL , PROGRAM , TYPE , SQL_ADDRESS ,
  128.   SQL_HASH_VALUE, SQL_ID, SQL_CHILD_NUMBER , SQL_EXEC_START, SQL_EXEC_ID,
  129.   PREV_SQL_ADDR , PREV_HASH_VALUE , PREV_SQL_ID, PREV_CHILD_NUMBER ,
  130.   PREV_EXEC_START , PREV_EXEC_ID , PLSQL_ENTRY_OBJECT_ID,
  131.   PLSQL_ENTRY_SUBPROGRAM_ID, PLSQL_OBJECT_ID, PLSQL_SUBPROGRAM_ID, MODULE ,
  132.   MODULE_HASH , ACTION , ACTION_HASH , CLIENT_INFO , FIXED_TABLE_SEQUENCE ,
  133.   ROW_WAIT_OBJ# , ROW_WAIT_FILE# , ROW_WAIT_BLOCK# , ROW_WAIT_ROW# ,
  134.   TOP_LEVEL_CALL#, LOGON_TIME , LAST_CALL_ET , PDML_ENABLED , FAILOVER_TYPE
  135.   , FAILOVER_METHOD , FAILED_OVER, RESOURCE_CONSUMER_GROUP, PDML_STATUS,
  136.   PDDL_STATUS, PQ_STATUS, CURRENT_QUEUE_DURATION, CLIENT_IDENTIFIER,
  137.   BLOCKING_SESSION_STATUS, BLOCKING_INSTANCE, BLOCKING_SESSION,
  138.   FINAL_BLOCKING_SESSION_STATUS, FINAL_BLOCKING_INSTANCE,
  139.   FINAL_BLOCKING_SESSION, SEQ#, EVENT#,EVENT,P1TEXT,P1,P1RAW,P2TEXT,P2,P2RAW,
  140.   P3TEXT,P3,P3RAW,WAIT_CLASS_ID, WAIT_CLASS#,WAIT_CLASS,WAIT_TIME,
  141.   SECONDS_IN_WAIT,STATE,WAIT_TIME_MICRO,TIME_REMAINING_MICRO,
  142.   TIME_SINCE_LAST_WAIT_MICRO,SERVICE_NAME, SQL_TRACE, SQL_TRACE_WAITS,
  143.   SQL_TRACE_BINDS, SQL_TRACE_PLAN_STATS, SESSION_EDITION_ID, CREATOR_ADDR,
  144.   CREATOR_SERIAL#, ECID
  145. from
  146.  GV$SESSION where inst_id = USERENV(\‘Instance\‘)


  147. call count cpu elapsed disk query current rows
  148. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  149. Parse 1 0.01 0.01 0 0 0 0
  150. Execute 0 0.00 0.00 0 0 0 0
  151. Fetch 0 0.00 0.00 0 0 0 0
  152. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  153. total 1 0.01 0.01 0 0 0 0

  154. Misses in library cache during parse: 1
  155. Optimizer mode: CHOOSE
  156. Parsing user id: SYS (recursive depth: 1)
  157. ********************************************************************************

  158. SQL ID: gzp9y42kcbx6m Plan Hash: 644658511

  159. select sid,serial#,username
  160. from
  161.  v$session where username=\‘SCOTT\‘


  162. call count cpu elapsed disk query current rows
  163. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  164. Parse 1 0.00 0.00 0 0 0 0
  165. Execute 1 0.00 0.00 0 0 0 0
  166. Fetch 2 0.00 0.00 0 0 0 1
  167. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  168. total 4 0.00 0.00 0 0 0 1

  169. Misses in library cache during parse: 1
  170. Optimizer mode: ALL_ROWS
  171. Parsing user id: SYS
  172. Number of plan statistics captured: 1

  173. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  174. ---------- ---------- ---------- ---------------------------------------------------
  175.          1 1 1 NESTED LOOPS (cr=0 pr=0 pw=0 time=231 us cost=0 size=121 card=1)
  176.          1 1 1 NESTED LOOPS (cr=0 pr=0 pw=0 time=2330 us cost=0 size=108 card=1)
  177.          1 1 1 FIXED TABLE FULL X$KSUSE (cr=0 pr=0 pw=0 time=1981 us cost=0 size=82 card=1)
  178.          1 1 1 FIXED TABLE FIXED INDEX X$KSLWT (ind:1) (cr=0 pr=0 pw=0 time=339 us cost=0 size=26 card=1)
  179.          1 1 1 FIXED TABLE FIXED INDEX X$KSLED (ind:2) (cr=0 pr=0 pw=0 time=2 us cost=0 size=13 card=1)

  180. ********************************************************************************

  181. SQL ID: 3nkd3g3ju5ph1 Plan Hash: 2853959010

  182. select obj#,type#,ctime,mtime,stime, status, dataobj#, flags, oid$, spare1,
  183.   spare2
  184. from
  185.  obj$ where owner#=:1 and name=:2 and namespace=:3 and remoteowner is null
  186.   and linkname is null and subname is null


  187. call count cpu elapsed disk query current rows
  188. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  189. Parse 1 0.00 0.00 0 0 0 0
  190. Execute 4 0.00 0.00 0 0 0 0
  191. Fetch 4 0.00 0.00 0 16 0 4
  192. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  193. total 9 0.00 0.00 0 16 0 4

  194. Misses in library cache during parse: 1
  195. Misses in library cache during execute: 1
  196. Optimizer mode: CHOOSE
  197. Parsing user id: SYS (recursive depth: 1)
  198. Number of plan statistics captured: 1

  199. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  200. ---------- ---------- ---------- ---------------------------------------------------
  201.          1 1 1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=4 pr=0 pw=0 time=145 us cost=4 size=82 card=1)
  202.          1 1 1 INDEX RANGE SCAN I_OBJ2 (cr=3 pr=0 pw=0 time=109 us cost=3 size=0 card=1)(object id 37)

  203. ********************************************************************************

  204. SQL ID: 7ng34ruy5awxq Plan Hash: 2542797530

  205. select i.obj#,i.ts#,i.file#,i.block#,i.intcols,i.type#,i.flags,i.property,
  206.   i.pctfree$,i.initrans,i.maxtrans,i.blevel,i.leafcnt,i.distkey,i.lblkkey,
  207.   i.dblkkey,i.clufac,i.cols,i.analyzetime,i.samplesize,i.dataobj#,
  208.   nvl(i.degree,1),nvl(i.instances,1),i.rowcnt,mod(i.pctthres$,256),
  209.   i.indmethod#,i.trunccnt,nvl(c.unicols,0),nvl(c.deferrable#+c.valid#,0),
  210.   nvl(i.spare1,i.intcols),i.spare4,i.spare2,i.spare6,decode(i.pctthres$,null,
  211.   null,mod(trunc(i.pctthres$/256),256)),ist.cachedblk,ist.cachehit,
  212.   ist.logicalread
  213. from
  214.  ind$ i, ind_stats$ ist, (select enabled, min(cols) unicols,
  215.   min(to_number(bitand(defer,1))) deferrable#,min(to_number(bitand(defer,4)))
  216.   valid# from cdef$ where obj#=:1 and enabled > 1 group by enabled) c where
  217.   i.obj#=c.enabled(+) and i.obj# = ist.obj#(+) and i.bo#=:1 order by i.obj#


  218. call count cpu elapsed disk query current rows
  219. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  220. Parse 1 0.00 0.00 0 0 0 0
  221. Execute 5 0.00 0.00 0 0 0 0
  222. Fetch 10 0.00 0.00 0 36 0 5
  223. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  224. total 16 0.00 0.00 0 36 0 5

  225. Misses in library cache during parse: 1
  226. Misses in library cache during execute: 1
  227. Optimizer mode: CHOOSE
  228. Parsing user id: SYS (recursive depth: 2)
  229. Number of plan statistics captured: 1

  230. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  231. ---------- ---------- ---------- ---------------------------------------------------
  232.          1 1 1 SORT ORDER BY (cr=8 pr=0 pw=0 time=644 us cost=7 size=372 card=2)
  233.          1 1 1 HASH JOIN OUTER (cr=8 pr=0 pw=0 time=608 us cost=6 size=372 card=2)
  234.          1 1 1 NESTED LOOPS OUTER (cr=5 pr=0 pw=0 time=177 us cost=2 size=286 card=2)
  235.          1 1 1 TABLE ACCESS CLUSTER IND$ (cr=4 pr=0 pw=0 time=100 us cost=2 size=182 card=2)
  236.          1 1 1 INDEX UNIQUE SCAN I_OBJ# (cr=2 pr=0 pw=0 time=38 us cost=1 size=0 card=1)(object id 3)
  237.          0 0 0 TABLE ACCESS BY INDEX ROWID IND_STATS$ (cr=1 pr=0 pw=0 time=71 us cost=0 size=52 card=1)
  238.          0 0 0 INDEX UNIQUE SCAN I_IND_STATS$_OBJ# (cr=1 pr=0 pw=0 time=66 us cost=0 size=0 card=1)(object id 433)
  239.          0 0 0 VIEW (cr=3 pr=0 pw=0 time=202 us cost=3 size=43 card=1)
  240.          0 0 0 SORT GROUP BY (cr=3 pr=0 pw=0 time=200 us cost=3 size=15 card=1)
  241.          0 0 0 TABLE ACCESS CLUSTER CDEF$ (cr=3 pr=0 pw=0 time=149 us cost=2 size=15 card=1)
  242.          1 1 1 INDEX UNIQUE SCAN I_COBJ# (cr=2 pr=0 pw=0 time=43 us cost=1 size=0 card=1)(object id 30)

  243. ********************************************************************************

  244. SQL ID: 5n1fs4m2n2y0r Plan Hash: 299250003

  245. select pos#,intcol#,col#,spare1,bo#,spare2,spare3
  246. from
  247.  icol$ where obj#=:1


  248. call count cpu elapsed disk query current rows
  249. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  250. Parse 1 0.00 0.00 0 0 0 0
  251. Execute 5 0.00 0.00 0 0 0 0
  252. Fetch 20 0.00 0.00 0 40 0 15
  253. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  254. total 26 0.00 0.00 0 40 0 15

  255. Misses in library cache during parse: 1
  256. Misses in library cache during execute: 1
  257. Optimizer mode: CHOOSE
  258. Parsing user id: SYS (recursive depth: 2)
  259. Number of plan statistics captured: 1

  260. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  261. ---------- ---------- ---------- ---------------------------------------------------
  262.          1 1 1 TABLE ACCESS BY INDEX ROWID ICOL$ (cr=4 pr=0 pw=0 time=52 us cost=2 size=54 card=2)
  263.          1 1 1 INDEX RANGE SCAN I_ICOL1 (cr=3 pr=0 pw=0 time=48 us cost=1 size=0 card=2)(object id 42)

  264. ********************************************************************************

  265. SQL ID: 83taa7kaw59c1 Plan Hash: 3765558045

  266. select name,intcol#,segcol#,type#,length,nvl(precision#,0),decode(type#,2,
  267.   nvl(scale,-127/*MAXSB1MINAL*/),178,scale,179,scale,180,scale,181,scale,182,
  268.   scale,183,scale,231,scale,0),null$,fixedstorage,nvl(deflength,0),default$,
  269.   rowid,col#,property, nvl(charsetid,0),nvl(charsetform,0),spare1,spare2,
  270.   nvl(spare3,0)
  271. from
  272.  col$ where obj#=:1 order by intcol#


  273. call count cpu elapsed disk query current rows
  274. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  275. Parse 1 0.00 0.00 0 0 0 0
  276. Execute 5 0.00 0.00 0 0 0 0
  277. Fetch 31 0.00 0.00 0 16 0 26
  278. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  279. total 37 0.00 0.00 0 16 0 26

  280. Misses in library cache during parse: 1
  281. Misses in library cache during execute: 1
  282. Optimizer mode: CHOOSE
  283. Parsing user id: SYS (recursive depth: 2)
  284. Number of plan statistics captured: 1

  285. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  286. ---------- ---------- ---------- ---------------------------------------------------
  287.          4 4 4 SORT ORDER BY (cr=4 pr=0 pw=0 time=54 us cost=3 size=708 card=12)
  288.          4 4 4 TABLE ACCESS CLUSTER COL$ (cr=4 pr=0 pw=0 time=27 us cost=2 size=708 card=12)
  289.          1 1 1 INDEX UNIQUE SCAN I_OBJ# (cr=2 pr=0 pw=0 time=9 us cost=1 size=0 card=1)(object id 3)

  290. ********************************************************************************

  291. SQL ID: 3ktacv9r56b51 Plan Hash: 4184428695

  292. select owner#,name,namespace,remoteowner,linkname,p_timestamp,p_obj#,
  293.   nvl(property,0),subname,type#,d_attrs
  294. from
  295.  dependency$ d, obj$ o where d_obj#=:1 and p_obj#=obj#(+) order by order#


  296. call count cpu elapsed disk query current rows
  297. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  298. Parse 2 0.00 0.00 0 0 0 0
  299. Execute 2 0.00 0.00 0 0 0 0
  300. Fetch 12 0.00 0.00 0 27 0 10
  301. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  302. total 16 0.00 0.00 0 27 0 10

  303. Misses in library cache during parse: 1
  304. Misses in library cache during execute: 1
  305. Optimizer mode: CHOOSE
  306. Parsing user id: SYS (recursive depth: 1)
  307. Number of plan statistics captured: 2

  308. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  309. ---------- ---------- ---------- ---------------------------------------------------
  310.          1 5 9 SORT ORDER BY (cr=14 pr=0 pw=0 time=304 us cost=11 size=330 card=3)
  311.          1 5 9 NESTED LOOPS OUTER (cr=14 pr=0 pw=0 time=297 us cost=10 size=330 card=3)
  312.          1 5 9 TABLE ACCESS BY INDEX ROWID DEPENDENCY$ (cr=4 pr=0 pw=0 time=80 us cost=4 size=84 card=3)
  313.          1 5 9 INDEX RANGE SCAN I_DEPENDENCY1 (cr=3 pr=0 pw=0 time=51 us cost=3 size=0 card=3)(object id 106)
  314.          1 3 5 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=10 pr=0 pw=0 time=157 us cost=2 size=82 card=1)
  315.          1 3 5 INDEX RANGE SCAN I_OBJ1 (cr=6 pr=0 pw=0 time=97 us cost=1 size=0 card=1)(object id 36)

  316. ********************************************************************************

  317. SQL ID: 87gaftwrm2h68 Plan Hash: 1218588913

  318. select o.owner#,o.name,o.namespace,o.remoteowner,o.linkname,o.subname
  319. from
  320.  obj$ o where o.obj#=:1


  321. call count cpu elapsed disk query current rows
  322. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  323. Parse 1 0.00 0.00 0 0 0 0
  324. Execute 1 0.00 0.00 0 0 0 0
  325. Fetch 1 0.00 0.00 0 3 0 1
  326. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  327. total 3 0.00 0.00 0 3 0 1

  328. Misses in library cache during parse: 1
  329. Misses in library cache during execute: 1
  330. Optimizer mode: CHOOSE
  331. Parsing user id: SYS (recursive depth: 2)
  332. Number of plan statistics captured: 1

  333. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  334. ---------- ---------- ---------- ---------------------------------------------------
  335.          1 1 1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=3 pr=0 pw=0 time=38 us cost=3 size=82 card=1)
  336.          1 1 1 INDEX RANGE SCAN I_OBJ1 (cr=2 pr=0 pw=0 time=31 us cost=2 size=0 card=1)(object id 36)

  337. ********************************************************************************

  338. SQL ID: ga9j9xk5cy9s0 Plan Hash: 1697022209

  339. select /*+ index(idl_sb4$ i_idl_sb41) +*/ piece#,length,piece
  340. from
  341.  idl_sb4$ where obj#=:1 and part=:2 and version=:3 order by piece#


  342. call count cpu elapsed disk query current rows
  343. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  344. Parse 3 0.00 0.00 0 0 0 0
  345. Execute 3 0.00 0.00 0 0 0 0
  346. Fetch 7 0.00 0.00 1 18 0 4
  347. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  348. total 13 0.00 0.00 1 18 0 4

  349. Misses in library cache during parse: 1
  350. Misses in library cache during execute: 1
  351. Optimizer mode: CHOOSE
  352. Parsing user id: SYS (recursive depth: 1)
  353. Number of plan statistics captured: 3

  354. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  355. ---------- ---------- ---------- ---------------------------------------------------
  356.          2 1 2 TABLE ACCESS BY INDEX ROWID IDL_SB4$ (cr=5 pr=0 pw=0 time=205 us cost=3 size=19 card=1)
  357.          2 1 2 INDEX RANGE SCAN I_IDL_SB41 (cr=3 pr=0 pw=0 time=36 us cost=2 size=0 card=1)(object id 239)

  358. ********************************************************************************

  359. SQL ID: cvn54b7yz0s8u Plan Hash: 3246118364

  360. select /*+ index(idl_ub1$ i_idl_ub11) +*/ piece#,length,piece
  361. from
  362.  idl_ub1$ where obj#=:1 and part=:2 and version=:3 order by piece#


  363. call count cpu elapsed disk query current rows
  364. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  365. Parse 3 0.00 0.00 0 0 0 0
  366. Execute 3 0.00 0.00 0 0 0 0
  367. Fetch 6 0.00 0.00 3 20 0 5
  368. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  369. total 12 0.00 0.00 3 20 0 5

  370. Misses in library cache during parse: 1
  371. Misses in library cache during execute: 1
  372. Optimizer mode: CHOOSE
  373. Parsing user id: SYS (recursive depth: 1)
  374. Number of plan statistics captured: 3

  375. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  376. ---------- ---------- ---------- ---------------------------------------------------
  377.          1 2 2 TABLE ACCESS BY INDEX ROWID IDL_UB1$ (cr=5 pr=1 pw=0 time=160 us cost=3 size=44 card=2)
  378.          1 2 2 INDEX RANGE SCAN I_IDL_UB11 (cr=3 pr=0 pw=0 time=30 us cost=2 size=0 card=2)(object id 236)

  379. ********************************************************************************

  380. SQL ID: c6awqs517jpj0 Plan Hash: 1319326155

  381. select /*+ index(idl_char$ i_idl_char1) +*/ piece#,length,piece
  382. from
  383.  idl_char$ where obj#=:1 and part=:2 and version=:3 order by piece#


  384. call count cpu elapsed disk query current rows
  385. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  386. Parse 3 0.00 0.00 0 0 0 0
  387. Execute 3 0.00 0.00 0 0 0 0
  388. Fetch 4 0.00 0.01 1 9 0 1
  389. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  390. total 10 0.00 0.01 1 9 0 1

  391. Misses in library cache during parse: 1
  392. Misses in library cache during execute: 1
  393. Optimizer mode: CHOOSE
  394. Parsing user id: SYS (recursive depth: 1)
  395. Number of plan statistics captured: 3

  396. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  397. ---------- ---------- ---------- ---------------------------------------------------
  398.          1 0 1 TABLE ACCESS BY INDEX ROWID IDL_CHAR$ (cr=3 pr=0 pw=0 time=3509 us cost=3 size=21 card=1)
  399.          1 0 1 INDEX RANGE SCAN I_IDL_CHAR1 (cr=2 pr=0 pw=0 time=30 us cost=2 size=0 card=1)(object id 237)

  400. ********************************************************************************

  401. SQL ID: 39m4sx9k63ba2 Plan Hash: 2317816222

  402. select /*+ index(idl_ub2$ i_idl_ub21) +*/ piece#,length,piece
  403. from
  404.  idl_ub2$ where obj#=:1 and part=:2 and version=:3 order by piece#


  405. call count cpu elapsed disk query current rows
  406. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  407. Parse 3 0.00 0.00 0 0 0 0
  408. Execute 3 0.00 0.00 0 0 0 0
  409. Fetch 4 0.00 0.00 1 11 0 2
  410. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  411. total 10 0.00 0.01 1 11 0 2

  412. Misses in library cache during parse: 1
  413. Misses in library cache during execute: 1
  414. Optimizer mode: CHOOSE
  415. Parsing user id: SYS (recursive depth: 1)
  416. Number of plan statistics captured: 3

  417. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  418. ---------- ---------- ---------- ---------------------------------------------------
  419.          2 1 2 TABLE ACCESS BY INDEX ROWID IDL_UB2$ (cr=3 pr=0 pw=0 time=2460 us cost=3 size=40 card=2)
  420.          2 1 2 INDEX RANGE SCAN I_IDL_UB21 (cr=2 pr=0 pw=0 time=29 us cost=2 size=0 card=2)(object id 238)

  421. ********************************************************************************

  422. SQL ID: 83sp8xb9ytgkv Plan Hash: 0

  423. BEGIN dbms_system.set_ev(21,2615,10046,12,\‘SCOTT\‘); END;


  424. call count cpu elapsed disk query current rows
  425. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  426. Parse 1 0.00 0.00 0 0 0 0
  427. Execute 1 0.00 0.00 0 0 0 1
  428. Fetch 0 0.00 0.00 0 0 0 0
  429. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  430. total 2 0.00 0.00 0 0 0 1

  431. Misses in library cache during parse: 1
  432. Optimizer mode: ALL_ROWS
  433. Parsing user id: SYS
  434. ********************************************************************************

  435. SQL ID: b1wc53ddd6h3p Plan Hash: 1637390370

  436. select audit$,options
  437. from
  438.  procedure$ where obj#=:1


  439. call count cpu elapsed disk query current rows
  440. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  441. Parse 2 0.00 0.00 0 0 0 0
  442. Execute 2 0.00 0.00 0 0 0 0
  443. Fetch 2 0.00 0.00 0 6 0 2
  444. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  445. total 6 0.00 0.00 0 6 0 2

  446. Misses in library cache during parse: 1
  447. Misses in library cache during execute: 1
  448. Optimizer mode: CHOOSE
  449. Parsing user id: SYS (recursive depth: 1)
  450. Number of plan statistics captured: 2

  451. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  452. ---------- ---------- ---------- ---------------------------------------------------
  453.          1 1 1 TABLE ACCESS BY INDEX ROWID PROCEDURE$ (cr=3 pr=0 pw=0 time=46 us cost=2 size=47 card=1)
  454.          1 1 1 INDEX UNIQUE SCAN I_PROCEDURE1 (cr=2 pr=0 pw=0 time=26 us cost=1 size=0 card=1)(object id 231)

  455. ********************************************************************************

  456. SQL ID: 8swypbbr0m372 Plan Hash: 893970548

  457. select order#,columns,types
  458. from
  459.  access$ where d_obj#=:1


  460. call count cpu elapsed disk query current rows
  461. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  462. Parse 2 0.00 0.00 0 0 0 0
  463. Execute 2 0.00 0.00 0 0 0 0
  464. Fetch 9 0.00 0.00 0 18 0 7
  465. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  466. total 13 0.00 0.00 0 18 0 7

  467. Misses in library cache during parse: 1
  468. Misses in library cache during execute: 1
  469. Optimizer mode: CHOOSE
  470. Parsing user id: SYS (recursive depth: 1)
  471. Number of plan statistics captured: 2

  472. Rows (1st) Rows (avg) Rows (max) Row Source Operation
  473. ---------- ---------- ---------- ---------------------------------------------------
  474.          7 4 7 TABLE ACCESS BY INDEX ROWID ACCESS$ (cr=9 pr=0 pw=0 time=56 us cost=3 size=161 card=7)
  475.          7 4 7 INDEX RANGE SCAN I_ACCESS1 (cr=6 pr=0 pw=0 time=48 us cost=2 size=0 card=7)(object id 108)




  476. ********************************************************************************

  477. OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

  478. call count cpu elapsed disk query current rows
  479. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  480. Parse 3 0.00 0.00 0 0 0 0
  481. Execute 4 0.01 0.01 0 0 0 1
  482. Fetch 4 0.01 0.01 0 0 0 2
  483. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  484. total 11 0.02 0.03 0 0 0 3

  485. Misses in library cache during parse: 3
  486. Misses in library cache during execute: 2


  487. OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

  488. call count cpu elapsed disk query current rows
  489. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  490. Parse 27 0.03 0.03 0 0 0 0
  491. Execute 61 0.01 0.02 0 0 0 0
  492. Fetch 133 0.01 0.02 6 286 0 103
  493. ------- ------ -------- ---------- ---------- ---------- ---------- ----------
  494. total 221 0.06 0.08 6 286 0 103

  495. Misses in library cache during parse: 16
  496. Misses in library cache during execute: 15

  497.     4 user SQL statements in session.
  498.    27 internal SQL statements in session.
  499.    31 SQL statements in session.
  500. ********************************************************************************
  501. Trace file: HOEGH_ora_16427.trc
  502. Trace file compatibility: 11.1.0.7
  503. Sort options: default

  504.        1 session in tracefile.
  505.        4 user SQL statements in trace file.
  506.       27 internal SQL statements in trace file.
  507.       31 SQL statements in trace file.
  508.       20 unique SQL statements in trace file.
  509.      534 lines in trace file.
  510.      337 elapsed seconds in trace file.


如何使用SQL_TRACE和10046事件

原文:http://blog.itpub.net/30162081/viewspace-1666982/

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!