可以这样做,用sys加一个logon on database的事件触发器,在其中判断是否你的应用程序连接的数据库,如果是,就启动跟踪,否则不跟踪。
create or replace trigger login_on_info
after logon on database
declare
v_serial int;
v_user int;
v_sid int;
Begin
if USERENV('SESSIONID')>0 then
begin
select sid,serial#,user# into v_sid,v_serial,v_user from v$session where audsid=userenv('sessionid');
if v_user=41 then --此处是判断用户ID是41就跟踪
dbms_system.set_sql_trace_in_session(v_sid,v_serial, TRUE);
end if;
exception when others then null;
end;
end if;
END;
/
create or replace trigger login_on_info
after logon on database
declare
v_serial int;
v_user int;
v_sid int;
Begin
if USERENV('SESSIONID')>0 then
begin
select sid,serial#,user# into v_sid,v_serial,v_user from v$session where audsid=userenv('sessionid');
if v_user=41 then --此处是判断用户ID是41就跟踪
dbms_system.set_sql_trace_in_session(v_sid,v_serial, TRUE);
end if;
exception when others then null;
end;
end if;
END;
/
*** SERVICE NAME:(tgas) 2005-09-20 15:22:35.953
*** SESSION ID:(137.1273) 2005-09-20 15:22:35.953
Skipped error 4098 during the execution of TGAS.LOGIN_ON_INFO
*** 2005-09-20 15:22:36.000
ksedmp: internal or fatal error
ORA-04098: trigger 'TGAS.LOGIN_ON_INFO' is invalid and failed re-validation
但是不影响程序的运行,请问是怎么回事?
谢谢.
现在的sql_trace是false.
如果用sys加一个logon on database的事件触发器,那不是一直在执行trace吗?trace是比较消耗资源的,肯定只有在定位问题时打开啊.