一般来说, 使用 10046 事件得到 sql 执行计划的步骤如下:
1. 激活当前 session 10046 事件
2. 在当前 session 中执行 sql 语句
3. 关闭当前 session 10046 事件
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_dump_dest string g:\app\davidd\diag\rdbms\david
\david\trace
刚刚提到的 oradebug 激活跟踪 10046 事件, 我想大部分 dba 都会使用. oradebug 是个功能强大非常好用的工具, 使用 oradebug help 将会看到它的功能很多
SQL> oradebug help HELP [command] Describe one or all commands SETMYPID Debug current process SETOSPID使用 oradebug 跟踪 10046 命令如下:Set OS pid of process to debug SETORAPID ['force'] Set Oracle pid of process to debug SETORAPNAME Set Oracle process name to debug SHORT_STACK Get abridged OS stack CURRENT_SQL Get current SQL DUMP [addr] Invoke named dump DUMPSGA [bytes] Dump fixed SGA DUMPLIST Print a list of available dumps EVENT Set trace event in process SESSION_EVENT Set trace event in session DUMPVAR
[level] Print/dump a fixed PGA/SGA/UGA variable DUMPTYPE Print/dump an address with type info SETVAR
Modify a fixed PGA/SGA/UGA variable PEEK [level] Print/Dump memory POKE Modify memory WAKEUP Wake up Oracle process SUSPEND Suspend execution RESUME Resume execution FLUSH Flush pending writes to trace file CLOSE_TRACE Close trace file TRACEFILE_NAME Get name of trace file LKDEBUG Invoke global enqueue service debugger NSDBX Invoke CGS name-service debugger -G Parallel oradebug command prefix -R Parallel oradebug prefix (return output SETINST Set instance list in double quotes SGATOFILE Dump SGA to file; dirname in double quotes DMPCOWSGA Dump & map SGA as COW; dirname in double quotes MAPCOWSGA Map SGA as COW; dirname in double quotes HANGANALYZE [level] [syslevel] Analyze system hang FFBEGIN Flash Freeze the Instance FFDEREGISTER FF deregister instance from cluster FFTERMINST Call exit and terminate instance FFRESUMEINST Resume the flash frozen instance FFSTATUS Flash freeze status of instance SKDSTTPCS Helps translate PCs to names WATCH Watch a region of memory DELETE watchpoint Delete a watchpoint SHOW watchpoints Show watchpoints DIRECT_ACCESS Fixed table access CORE Dump core without crashing process IPC Dump ipc information UNLIMIT Unlimit the size of the trace file PROCSTAT Dump process statistics CALL [arg1] ... [argn] Invoke function with arguments
SQL> oradebug setmypid Statement processed. // 激活 10046 事件 SQL> oradebug event 10046 trace name context forever,level 12; Statement processed. SQL> select /*+ leading(t3) use_merge(t4) */ * 2 from t3, t4 3 where t3.id = t4.t3_id and t3.n = 1100; 10 rows selected. // 在当前 session 关闭 10046 事件 SQL> oradebug event 10046 trace name context off; Statement processed. // 使用 oradebug tracefile_name 可以直接看到生成的 trace 文件的位置 SQL> oradebug tracefile_name; g:\app\davidd\diag\rdbms\david\david\trace\david_ora_2176.trc
其中, 10046 按照收集信息的内容分为以下等级:
?
| Level 0 | 停用SQL跟踪,相当于SQL_TRACE=FALSE |
| Lev |