用户登陆即抓取trace文件

CREATE OR REPLACE TRIGGER tr_login_record
  AFTER logon ON DATABASE
DECLARE
  miUserSid NUMBER;
  miSerial number;
BEGIN
  SELECT sid INTO miUserSid FROM sys.v_$mystat WHERE rownum <= 1;
  select sid,serial# into miUserSid,miSerial from sys.v_$session where sid=miUserSid and username='CAS_ADMIN' and lower(machine) like '%alex%';
  if (miUserSid is not null) and (miSerial is not null) then
	execute immediate 'begin dbms_system.set_sql_trace_in_session('||miUserSid||','||miSerial||',true); end;';
	end if;
EXCEPTION
  WHEN OTHERS THEN
    dbms_output.put_line('Login Trigger Error:' || SQLERRM);
END tr_login_record;
/


drop TRIGGER tr_login_record;
Trackback

no comment untill now

Add your comment now

切换到手机版