开启跟踪事件
打开10046事件并设定级别为4:alter session set events '10046 trace name context forever, level 4';
关闭10046事件:alter session set events '10046 trace name context off';
查看寻10046生成的trace文件
select value from v$diag_info where name='Default Trace File';
用下面的方法对其他会话进行跟踪:
SQL_TRACE:
获取想要跟踪session的sid:select distinct sid from v$mystat;
获得需要trace会话的SID和serial#的值:select sid, serial# from v$session where sid=[SID];
启动SQL_TRACE: execute dbms_system.set_sql_trace_in_session([SID],[seial#],true); 需要sysdba权限
停止SQL_TRACE: execute dbms_system.set_sql_trace_in_session([SID],[seial#],false); 需要sysdba权限
10046事件:
获得需要trace会话的SID和serial#的值:select sid, serial# from v$session where sid=[SID];
启动SQL_TRACE: execute dbms_monitor.session_trace_enable([SID],[seial#],waits=>true,binds=>true);
停止SQL_TRACE: exec dbms_monitor.session.trace_disable([SID],[seial#]);
其中, 10046 按照收集信息的内容分为以下等级:
Level 0 停用SQL跟踪,相当于SQL_TRACE=FALSE
Level 1 标准SQL跟踪,相当于SQL_TRACE=TRUE
Level 4 在level 1的基础上增加绑定变量的信息
Level 8 在level 1的基础上增加等待事件的信息
Level 12 在level 1的基础上增加绑定变量和等待事件的信息
PARSING IN CURSOR #140397889619520 len=70 dep=1 uid=0 oct=3 lid=0 tim=1495445064661679 hv=3849548163 ad='887f8898' sqlid='53saa2zkr6wc3'
cursor cursor number
len sql 语句长度
dep sql 语句递归深度
uid user id
oct oracle command type
lid privilege user id
tim timestamp,时间戳
hv hash id
ad sql address 地址, 用在 v$sqltext
sqlid sql id
EXEC #140397889619520:c=0,e=110,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=1514015273,tim=1495445064661771
WAIT #140397889619520: nam='db file sequential read' ela= 652 file#=1 block#=79197 blocks=1 obj#=58 tim=1495445064662479
FETCH #140397889619520:c=4998,e=783,p=1,cr=3,cu=0,mis=0,r=1,dep=1,og=4,plh=1514015273,tim=1495445064662578
c CPU 消耗的时间
e Elapsed time
p number of physical reads 物理读的次数
cr number of buffers retrieved for CR reads 逻辑读的数据块
cu number of buffers retrieved in current mode (current 模式读取的数据块)
mis cursor missed in the cache 库缓存中丢失的游标, 硬解析次数
r number of rows processed 处理的行数
dep 递归深度
og optimizer mode 【1:all_rows, 2:first_rows, 3:rule, 4:choose】
plh plan hash value
tim timestamp 时间戳
WAIT #140397889619520: nam='db file sequential read' ela= 652 file#=1 block#=79197 blocks=1 obj#=58 tim=1495445064662479
nam an event that we waited for 等待事件
ela 此操作消耗的时间
p3 block 块号
trm timestamp 时间戳
STAT #140397883926128 id=1 cnt=1 pid=0 pos=1 obj=22 op='TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=29 us cost=1 size=104 card=1)'
cnt 当前行源返回的行数
pid parent id of this row source 当前行源的父结点 id
pos position in explain plan 执行计划的位置
obj object id of row source (if this is a base object)
op the row source access operation
例如, 执行步骤 TABLE ACCESS BY INDEX ROWID 消耗的逻辑读为 2, 物理读为 0, 耗费的时间为 29 us, 成本 cost 1,返回 1 条记录
使用 tkprof 命令翻译 trace 文件
我们也可以使用 tkprof 命令对 trace 文件进行翻译,得到一个容易理解的 trace 汇总报表文件
tkprof 1.txt 1.out
注意:Misses in library cache during parse: 1 意思是解析的时候库缓存丢失游标, 也就是说发生了一次硬解析
打开10046事件并设定级别为4:alter session set events '10046 trace name context forever, level 4';
关闭10046事件:alter session set events '10046 trace name context off';
查看寻10046生成的trace文件
select value from v$diag_info where name='Default Trace File';
用下面的方法对其他会话进行跟踪:
SQL_TRACE:
获取想要跟踪session的sid:select distinct sid from v$mystat;
获得需要trace会话的SID和serial#的值:select sid, serial# from v$session where sid=[SID];
启动SQL_TRACE: execute dbms_system.set_sql_trace_in_session([SID],[seial#],true); 需要sysdba权限
停止SQL_TRACE: execute dbms_system.set_sql_trace_in_session([SID],[seial#],false); 需要sysdba权限
10046事件:
获得需要trace会话的SID和serial#的值:select sid, serial# from v$session where sid=[SID];
启动SQL_TRACE: execute dbms_monitor.session_trace_enable([SID],[seial#],waits=>true,binds=>true);
停止SQL_TRACE: exec dbms_monitor.session.trace_disable([SID],[seial#]);
其中, 10046 按照收集信息的内容分为以下等级:
Level 0 停用SQL跟踪,相当于SQL_TRACE=FALSE
Level 1 标准SQL跟踪,相当于SQL_TRACE=TRUE
Level 4 在level 1的基础上增加绑定变量的信息
Level 8 在level 1的基础上增加等待事件的信息
Level 12 在level 1的基础上增加绑定变量和等待事件的信息
PARSING IN CURSOR #140397889619520 len=70 dep=1 uid=0 oct=3 lid=0 tim=1495445064661679 hv=3849548163 ad='887f8898' sqlid='53saa2zkr6wc3'
cursor cursor number
len sql 语句长度
dep sql 语句递归深度
uid user id
oct oracle command type
lid privilege user id
tim timestamp,时间戳
hv hash id
ad sql address 地址, 用在 v$sqltext
sqlid sql id
EXEC #140397889619520:c=0,e=110,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=1514015273,tim=1495445064661771
WAIT #140397889619520: nam='db file sequential read' ela= 652 file#=1 block#=79197 blocks=1 obj#=58 tim=1495445064662479
FETCH #140397889619520:c=4998,e=783,p=1,cr=3,cu=0,mis=0,r=1,dep=1,og=4,plh=1514015273,tim=1495445064662578
c CPU 消耗的时间
e Elapsed time
p number of physical reads 物理读的次数
cr number of buffers retrieved for CR reads 逻辑读的数据块
cu number of buffers retrieved in current mode (current 模式读取的数据块)
mis cursor missed in the cache 库缓存中丢失的游标, 硬解析次数
r number of rows processed 处理的行数
dep 递归深度
og optimizer mode 【1:all_rows, 2:first_rows, 3:rule, 4:choose】
plh plan hash value
tim timestamp 时间戳
WAIT #140397889619520: nam='db file sequential read' ela= 652 file#=1 block#=79197 blocks=1 obj#=58 tim=1495445064662479
nam an event that we waited for 等待事件
ela 此操作消耗的时间
p3 block 块号
trm timestamp 时间戳
STAT #140397883926128 id=1 cnt=1 pid=0 pos=1 obj=22 op='TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=29 us cost=1 size=104 card=1)'
cnt 当前行源返回的行数
pid parent id of this row source 当前行源的父结点 id
pos position in explain plan 执行计划的位置
obj object id of row source (if this is a base object)
op the row source access operation
例如, 执行步骤 TABLE ACCESS BY INDEX ROWID 消耗的逻辑读为 2, 物理读为 0, 耗费的时间为 29 us, 成本 cost 1,返回 1 条记录
使用 tkprof 命令翻译 trace 文件
我们也可以使用 tkprof 命令对 trace 文件进行翻译,得到一个容易理解的 trace 汇总报表文件
tkprof 1.txt 1.out
注意:Misses in library cache during parse: 1 意思是解析的时候库缓存丢失游标, 也就是说发生了一次硬解析
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30345407/viewspace-2139701/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30345407/viewspace-2139701/