您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

通过案例学调优之--10046事件

2025/8/10 6:45:26发布26次查看
通过案例学调优之--10046事件10046事件概述oracle的10046事件,可以跟踪应用程序所执行的sql语句,并且得到其解析次数.执行次数,cpu使用时间等信息。这对我们分
(先确保要event的会话环境符合条件)
1、必须确保timed_statistics为true,这个参数可以在会话级上进行修改。
关于参数timed_statistics的一段解释
      without timed statistics, oracle records the reason for each wait before it begins to wait, and when the wait is over, it records whether it timed out. but with timed statistics enabled, oracle checks the time just before and after each wait, and also records the time waited. the time waited is recorded in hundredths of a second— that is, centiseconds.
true
      the statistics are collected and stored in trace files or displayed in the v$sesstats and v$sysstats dynamic performance views.
false
     the value of all time-related statistics is set to zero. this setting lets oracle avoid the overhead of requesting the time from the operating system.
      starting with release 11.1.0.7.0, the value of the timed_statistics parameter cannot be set to false if the value of statistics_level is set to typical or all.
与sql trace相关的参数
在打开10046时间的sql trace之前,要先设置好下面几个参数。
timed_statistics
这个参数决定了是否收集与时间相关的统计信息,如果这个参数为false的话,那么sql trace的结果基本没有多大的用处,默认情况下这个参数设置为true。
max_dump_file_size
dump文件的大小,也就是决定是否限制sql trace文件的大小,在一个很忙的系统上面做sql trace的话可能会生成很多的信息,因此最好在会话级别将这个参数设置成unlimited。
tracefile_identifier
给trace文件设置识别字符串,这是个非常有用的参数,设置一个易读的字串能更快的找到trace文件。
要在当前会话修改上述参数很简单,只要使用下面的命令即可:
alter session set timed_statistics=truealter session set max_dump_file_size=unlimitedalter session set tracefile_identifier='my_trace_session
当然,这些参数可以在系统级别修改的,也可以加载init文件中或是spfile中,让系统启动时自动做全局设置。
要是在系统运行时动态的修改别的会话的这些参数就需要借助dbms_system这个包了,设置方法如下
sys.dbms_system.set_bool_param_in_session(  :sid, :serial,  'timed_statistics', true) sys.dbms_system.set_int_param_in_session(  :sid, :serial,  'max_dump_file_size', 2147483647)案例:
13:55:30 sys@ prod >select username,sid,serial# from v$session where username is not null;username                              sid    serial#------------------------------ ---------- ----------sys                                     1          5scott                                  40        587sys                                    48        56914:31:33 sys@ prod >desc dbms_systemprocedure add_parameter_value argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- parname                        varchar2                in value                          varchar2                in scope                          varchar2                in     default sid                            varchar2                in     default position                       binary_integer          in     defaultprocedure dist_txn_sync argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- inst_num                       number                  inprocedure get_env argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- var                            varchar2                in val                            varchar2                outprocedure kcfrmsprocedure ksdddtprocedure ksdflsprocedure ksdind argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- lvl                            binary_integer          inprocedure ksdwrt argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- dest                           binary_integer          in tst                            varchar2                inprocedure read_ev argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- iev                            binary_integer          in oev                            binary_integer          outprocedure remove_parameter_value argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- parname                        varchar2                in value                          varchar2                in scope                          varchar2                in     default sid                            varchar2                in     defaultprocedure remove_parameter_value argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- parname                        varchar2                in position                       binary_integer          in scope                          varchar2                in     default sid                            varchar2                in     defaultprocedure set_bool_param_in_session argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- sid                            number                  in serial#                        number                  in parnam                         varchar2                in bval                           boolean                 inprocedure set_ev argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- si                             binary_integer          in se                             binary_integer          in ev                             binary_integer          in le                             binary_integer          in nm                             varchar2                inprocedure set_int_param_in_session argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- sid                            number                  in serial#                        number                  in parnam                         varchar2                in intval                         binary_integer          inprocedure set_sql_trace_in_session argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- sid                            number                  in serial#                        number                  in sql_trace                      boolean                 inprocedure wait_for_event argument name                  type                    in/out default? ------------------------------ ----------------------- ------ -------- event                          varchar2                in extended_id                    binary_integer          in timeout                        binary_integer          in 14:28:02 sys@ prod >exec dbms_system.set_bool_param_in_session(40,587,'time_statistics',true);pl/sql procedure successfully completed.14:33:59 sys@ prod >exec dbms_system.set_int_param_in_session(40,587,'max_dump_file_size',2147364847);pl/sql procedure successfully completed.10046 trace启动方法
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product