下面是10046事件的几个等级分别表示什么意思

 
  
  1. Level 0 Tracing is disabled. This is the same as setting SQL_TRACE = FALSE
  2.  
  3. Level 1 Standard SQL trace information (SQL_TRACE = TRUE). This is the default level
  4.  
  5. Level 4 SQL trace information plus bind variable values
  6.  
  7. Level 8 SQL trace information plus wait event information. 
  8.  
  9. Level 12 SQL trace information, wait event information, and bind variable values

   下面是常见的几种方法

一、trace当前进程

 

 

 
  
  1. 1,event方法 
  2. alter session set timed_statistics = true
  3. alter session set max_dump_file_size = unlimited; 
  4. alter session set events '10046 trace name context forever, level 8'
  5. alter session set events '10046 trace name context off';     
  6.  
  7. 2,dbms_support方法 
  8. alter session set timed_statistics = true
  9. alter session set max_dump_file_size = unlimited; 
  10. exec sys.dbms_support.start_trace; 
  11. --To include Bind variable values, Wait Event data with SQL trace 
  12. exec sys.dbms_support.start_trace(waits => TRUE, binds=> TRUE
  13. exec sys.dbms_support.stop_trace; 
  14.  
  15. 3,oradebug 方法 
  16. alter system set timed_statistics = true
  17. SQL> oradebug setmypid 
  18. Statement processed. 
  19. SQL> oradebug unlimit; 
  20. Statement processed. 
  21. SQL> oradebug event 10046 trace name context forever,level 8 
  22. Statement processed. 

二,trace其它进程

 
  
  1.   在trace其它进程前,先修改下面两个参数的值 -- Set TIME_STATISTICS to TRUE for SID 10, Serial# 118 
  2. exec sys.dbms_system.set_bool_param_in_session(- 
  3. sid => 10, - 
  4. serial# => 118, - 
  5. parnam => 'TIMED_STATISTICS',- 
  6. bval => true); 
  7. -- Set MAX_DUMP_FILE_SIZE to 2147483647 
  8. -- for SID 10, Serial# 118 
  9. exec sys.dbms_system.set_int_param_in_session(- 
  10. sid => 10,- 
  11. serial# => 118,- 
  12. parnam => 'MAX_DUMP_FILE_SIZE',- 
  13. intval => 2147483647); 
  14.  
  15.  
  16. 1,使用dbms_support方法 
  17.  
  18. -- Enable ‘level 12’ trace in session 10 with serial# 118 
  19. exec dbms_support.start_trace_in_session(- 
  20. sid => 10,- 
  21. serial => 118,- 
  22. waits => true,- 
  23. binds => true); 
  24. -- Let the session execute SQL script or -- program for some amount of time  
  25. -- To turn off the tracing: 
  26. exec dbms_support.stop_trace_in_session(- 
  27. sid => 10, - 
  28. serial => 118); 
  29.  
  30. 2,使用DBMS_SYSTEM  
  31. -- Enable trace at level 8 for session 10 with serial# 118 
  32. exec dbms_system.set_ev( 10, 118, 10046, 8, '');   
  33. -- Let the session execute SQL script or-- program for some amount of time  
  34. -- To turn off the tracing: 
  35. exec dbms_system.set_ev( 10, 118, 10046, 0, ''); 
  36.  
  37. 3,使用oradebug工具 
  38. 在使用oradebug工具前,我们得先查找到sess在操作系统上面的进程号,可以使用下面的SQL来查询 
  39. select s.username,p.spid os_process_id,p.pid oracle_process_id from   v$session s, v$process p where  s.paddr = p.addr and s.sid=&sid; 
  40.  
  41. 查看进程号后,使用下面的命令 
  42. alter system set timed_statistics = true
  43. oradebug setospid 6509;   
  44. -- 6509 is the OS process id for the session 
  45. oradebug unlimit; 
  46. oradebug event 10046 trace name context forever, level 8; 
  47. -- Let the session execute SQL script  
  48. -- or program for some amount of time  
  49. -- To turn off the tracing: 
  50. oradebug event 10046 trace name context off
  51. 4,使用dbms_monitor 
  52. exec dbms_monitor.session_trace_enable( -      
  53. session_id => 10,-      
  54. serial_num => 118, -      
  55. waits => true, -      
  56. binds => true); 
  57. -- Let the session execute SQL script or -- program for some amount of time  
  58. -- To turn off the tracing: 
  59. exec dbms_monitor.session_trace_disable( -      
  60. session_id => 10, -      
  61. serial_num => 118);