您好,欢迎访问一九零五行业门户网

浅谈Oracle SQL trace

在生产环境中,当数据库运行异常缓慢的时候,dba同学们都会想冲进数据库内部看看sql到底如何运行,为何语句执行的如此缓慢?在我的生产环境中,经常有多表关联查
在生产环境中,当数据库运行异常缓慢的时候,dba同学们都会想冲进数据库内部看看sql到底如何运行,为何语句执行的如此缓慢?在我的生产环境中,经常有多表关联查询语句运行缓慢,多数是i/o等待的问题,因而我第一步会去看sql的执行计划是否出现了问题,其次就会用到sql trace工具来跟踪下sql的实际运行情况!
一:使用sql_trace
1:产生select语句的trace文件,一般会使用tracefile_identifier给trace文件起一个标识性的名称,香港服务器,便于查找
2:使用tkprof工具对产生的trace文件进行过滤,抽取有用的信息,默认的trace文件输出太多信息!
sys=no代表不输出trace文件中所有sys用户的操作,包含用户sql语句引起的递归sql,使输出变的简洁;
aggragate=yes代表相同的sql语句在输入文件中做合并,网站空间,使输出变的简洁;
[oracle@dg53 udump]$ tkprof dg53_ora_10498_hr_trace01.trc /home/oracle/trace01.log   aggregate=yes sys=no explain=hr/hr
[oracle@dg53 udump]$ wc -l dg53_ora_10498_hr_trace01.trc
1097 dg53_ora_10498_hr_trace01.trc
[oracle@dg53 udump]$ wc -l /home/oracle/trace01.log
137 /home/oracle/trace01.log
[oracle@dg53 ~]$ cat trace01.log
tkprof: release 10.2.0.1.0 - production on fri jun 8 12:06:23 2012
copyright (c) 1982, 2005, oracle.  all rights reserved.
trace file: dg53_ora_10498_hr_trace01.trc
sort options: default
********************************************************************************
count    = number of times oci procedure was executed
cpu      = cpu time in seconds executing
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
********************************************************************************
alter session set sql_trace=true
call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
parse        0      0.00       0.00          0          0          0           0
execute      1      0.00       0.01          0          0          0           0
fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        1      0.00       0.01          0          0          0           0
misses in library cache during parse: 0
misses in library cache during execute: 1
optimizer mode: all_rows
parsing user id: 55  (hr)
********************************************************************************
select salary,last_name
from
 employees where employee_id=100
call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
parse        1      0.00       0.02          0          0          0           0
execute      1      0.00       0.00          0          0          0           0
fetch        2      0.00       0.01          2          2          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.04          2          2          0           1
其它类似信息

推荐信息