时间:2021-07-01 10:21:17 帮助过:89人阅读
1.设置参数文件 设置三个参数timed_statistics、user_dump_dest、max_dump_file_size。 timed_staticstices 用于启动或禁止对定
1.设置参数文件 timed_staticstices
用于启动或禁止对定时统计信息(如CPU时间、占用时间),以及动态性能表中多种统计信息的收集功能
SQL>alter session set timed_statistics = true;
SQL>alter system set timed_statistics = true;
max_dump_file_size
当实例层启用SQL TRACE的时候,在每次请求服务器的时候,都将在跟踪文件中产生一个文本行,这些文件的最大尺寸受限于初始化参数的设置。默认为500(blocks)。若里面的数据被截断则增大SIZE。若为UNLIMITED则意味着没有上限。
user_dump_dest
设置跟踪文件的存储位置。默认为admin/用户/udump;
SQL>alter system set user_dump_dest = 'newdir';
2.启动SQL TRACE实用工具对会话启动关闭SQL TRACE
SQL>alter session set sql_trace = true;
SQL>alter session set sql_trace = false;
SQL>exec SYS.DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION =(SID,SERIAL#,TRUE);
SQL>exec SYS.DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION =(SID,SERIAL#,,FALSE);
对用户实例启动关闭SQL TRACE
SQL>alter system set sql_trace = true;
SQL>alter system set sql_trace = false;
3.使用tkprof格式化trace文件Usage
tkprof inputfile outputfile [optional | parameters ]
(tkprof tracefile outputfile [explain= ] [table= ] [print= ] [insert= ] [sys= ] [sort= ])
例:1.tkprof tracefile outfile [explain=user/password] [options...];
例:2.tkprof uat_ora_14936.trc trace.txt sort=(prsdsk,exedsk,fchdsk) print=10 explain=apps/apps table=apps.temp_plan_table_a insert=storea.sql sys=no
tkprof参数和选项
trace其他session
查询某用户的session的SID及SERIAL#
$sqlplus / as sysdba
SQL>select s.USERNAME,s.SID,s.SERIAL#,s.COMMAND from v$session s
where s.USERNAME='ETOH' ; --注意用户名用大写
SQL>exec dbms_system.SET_SQL_TRACE_IN_SESSION(12,73,true);
等待被跟踪session活动一段时间
SQL>exec dbms_system.SET_SQL_TRACE_IN_SESSION(12,73,false);
--查询生成的.trc文件号
SQL>SELECT d.value || '/' || lower(rtrim(i.instance, chr(0))) || '_ora_' ||
p.spid || '.trc' trace_file_name
from (select p.spid
from v$session s, v$process p
where s.sid = &sid
and s. SERIAL# = &serial#
and p.addr = s.paddr) p,
(select t.instance
from v$thread t, v$parameter v
where v.name = 'thread'
and (v.value = 0 or t.thread# = to_number(v.value))) i,
(select value from v$parameter where name = 'user_dump_dest') d;
--使用tkprof生成分析文件
$tkprof /u01/app/Oracle/admin/center/udump/
trace本session
查询本session信息
SQL>SELECT Sid, Serial# FROM V$session WHERE sid = Sys_Context ( 'USERENV' , 'SID' );
SQL>alter session set sql_trace=true;
SQL>#SQL Statements#
SQL>alter session set sql_trace=false;
查询生成的trace文件名
SQL>SELECT d.value || '/' || lower(rtrim(i.instance, chr(0))) || '_ora_' ||
p.spid || '.trc' trace_file_name
from (select p.spid
from v$mystat m, v$session s, v$process p
where m.statistic# = 1
and s.sid = m.sid
and p.addr = s.paddr) p,
(select t.instance
from v$thread t, v$parameter v
where v.name = 'thread'
and (v.value = 0 or t.thread# = to_number(v.value))) i,
(select value from v$parameter where name = 'user_dump_dest') d;
tkprof格式化处理
$tkprofcenter_ora_24012.trccenter_ora_24012.txt {一系列参数}