在做10046跟踪的时候,经常需要定位跟踪文件的位置。
alter session set events '10046 trace name context forever, level 8';
11g下,在v$process加入了tracefile字段。执行如下就可以知道。
select tracefile from v$process where addr = (select paddr from v$session where sid = userenv('sid'))
或者执行
select * from v$diag_info where name='Default Trace File';
10g下写出通用的脚本要复杂一点,如下:
链接:
http://allthingsoracle.com/dynamic-sampling-i-an-introduction-part-2/
SELECT value ||
CASE
WHEN instr(dbms_utility.port_string, 'WIN_NT') > 0 then '\'
ELSE '/'
END || (
SELECT instance_name FROM v$instance) || '_ora_' || (
SELECT spid ||
CASE
WHEN traceid is not null then '_' || traceid
ELSE null
END
FROM v$process
WHERE addr = (
SELECT paddr FROM v$session
WHERE sid = (
SELECT sid FROM v$mystat WHERE rownum = 1))) || '.trc' as tracefile
FROM v$parameter
WHERE name = 'user_dump_dest' ;
通过函数dbms_utility.port_string知道OS的操作系统类型,剩下的就简单了。