温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用10046查看执行计划并读懂trace文件

发布时间:2021-10-26 13:58:57 来源:亿速云 阅读:193 作者:小新 栏目:建站服务器

这篇文章给大家分享的是有关如何使用10046查看执行计划并读懂trace文件的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

查看 sql 执行计划的方法有许多种, 10046 事件就是其中的一种. 与其他查看 sql 执行计划不同, 当我们遇到比较复杂的 sql 语句, 我们可以通过 10046 跟踪 sql 得到执行计划中每一个步骤的逻辑读, 物理读以及花费的时间等. 这种细粒度的跟踪对于我们分析 sql 性能尤其有用.

一般来说, 使用 10046 事件得到 sql 执行计划的步骤如下:
1. 激活当前 session 10046 事件
2. 在当前 session 中执行 sql 语句
3. 关闭当前 session 10046 事件

执行完上述步骤后, 通常会自动生成一个 trace 文件. 在 oracle 11g 中, trace 文件一般放在$ORACLE_BASE/diag/rdbms/{database_name}/$ORACLE_SID/trace 目录下. 如果使用 oradebug 激活跟踪 10046后, 可以使用 oradebug tracefile_name 得到刚刚生成的 trace 文件的完整路径.

刚刚提到的 oradebug 激活跟踪 10046 事件, 我想大部分 dba 都会使用. oradebug 是个功能强大非常好用的工具, 使用 oradebug help 将会看到它的功能很多

  1. SQL> oradebug help

  2. HELP           [command]                 Describe one or all commands

  3. SETMYPID                                 Debug current process

  4. SETOSPID       <ospid>                   Set OS pid of process to debug

  5. SETORAPID      <orapid> ['force']         Set Oracle pid of process to debug

  6. SETORAPNAME    <orapname>                 Set Oracle process name to debug

  7. SHORT_STACK                               Get abridged OS stack

  8. CURRENT_SQL                               Get current SQL

  9. DUMP           <dump_name> <lvl> [addr]   Invoke named dump

  10. DUMPSGA        [bytes]                   Dump fixed SGA

  11. DUMPLIST                                 Print a list of available dumps

  12. EVENT          <text>                     Set trace event in process

  13. SESSION_EVENT  <text>                     Set trace event in session

  14. DUMPVAR        <p|s|uga> <name> [level]   Print/dump a fixed PGA/SGA/UGA variable

  15. DUMPTYPE       <address> <type> <count>   Print/dump an address with type info

  16. SETVAR         <p|s|uga> <name> <value>   Modify a fixed PGA/SGA/UGA variable

  17. PEEK           <addr> <len> [level]       Print/Dump memory

  18. POKE           <addr> <len> <value>       Modify memory

  19. WAKEUP         <orapid>                   Wake up Oracle process

  20. SUSPEND                                   Suspend execution

  21. RESUME                                   Resume execution

  22. FLUSH                                     Flush pending writes to trace file

  23. CLOSE_TRACE                               Close trace file

  24. TRACEFILE_NAME                           Get name of trace file

  25. LKDEBUG                                   Invoke global enqueue service debugger

  26. NSDBX                                     Invoke CGS name-service debugger

  27. -G             <Inst-List | def | all>   Parallel oradebug command prefix

  28. -R             <Inst-List | def | all>   Parallel oradebug prefix (return output

  29. SETINST        <instance# .. | all>       Set instance list in double quotes

  30. SGATOFILE      <SGA dump dir>             Dump SGA to file; dirname in double quotes

  31. DMPCOWSGA      <SGA dump dir> Dump & map SGA as COW; dirname in double quotes

  32. MAPCOWSGA      <SGA dump dir>             Map SGA as COW; dirname in double quotes

  33. HANGANALYZE    [level] [syslevel]         Analyze system hang

  34. FFBEGIN                                   Flash Freeze the Instance

  35. FFDEREGISTER                             FF deregister instance from cluster

  36. FFTERMINST                               Call exit and terminate instance

  37. FFRESUMEINST                             Resume the flash frozen instance

  38. FFSTATUS                                 Flash freeze status of instance

  39. SKDSTTPCS      <ifname>  <ofname>         Helps translate PCs to names

  40. WATCH          <address> <len> <self|exist|all|target>  Watch a region of memory

  41. DELETE         <local|global|target> watchpoint <id>    Delete a watchpoint

  42. SHOW           <local|global|target> watchpoints        Show  watchpoints

  43. DIRECT_ACCESS  <set/enable/disable command | select query> Fixed table access

  44. CORE                                     Dump core without crashing process

  45. IPC                                       Dump ipc information

  46. UNLIMIT                                   Unlimit the size of the trace file

  47. PROCSTAT                                 Dump process statistics

  48. CALL           <func> [arg1] ... [argn]   Invoke function with arguments

感谢各位的阅读!关于“如何使用10046查看执行计划并读懂trace文件”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI