[20130207]tracefile_identifier参数设置的问题.txt
设置tracefile_identifier参数的主要目的就是为了很好的定位跟踪文件。
我同事提出一个要求就是修改回话的tracefile_identifier包含IP地址。我做了一些简单的测试:
SQL> alter session set tracefile_identifier = aaa;
Session altered.
SQL> alter session set tracefile_identifier = 172;
Session altered.
--如果英文,数字(没有小数点)开头不需使用引号。
SQL> alter session set tracefile_identifier = 172.16.11.100;
alter session set tracefile_identifier = 172.16.11.100
*
ERROR at line 1:
ORA-02017: integer value required
--必须使用引号!
SQL> alter session set tracefile_identifier = '172.16.11.100';
Session altered.
SQL> column name format a20
SQL> column value new_value file format a86
SQL> select * from v$diag_info where name='Default Trace File';
INST_ID NAME VALUE
---------- -------------------- --------------------------------------------------------------------------------------
1 Default Trace File /u01/app/oracle11g/diag/rdbms/test/test/trace/test_ora_12667_172.16.11.100
--这样有1点小问题,生成的文件没有.trc后缀。
最后的代码如下:
/* Formatted on 2013/02/07 15:08 (Formatter Plus v4.8.8) */
--
-- ON_LOGON_TRIGGER (Trigger)
--
-- Dependencies:
-- STANDARD (Package)
-- DBMS_APPLICATION_INFO (Package)
-- V$SESSION (View)
-- V$MYSTAT (View)
--
CREATE OR REPLACE TRIGGER SYS.on_logon_trigger
AFTER LOGON ON DATABASE
DECLARE
v_client_info v$session.client_info%TYPE;
v_sid v$session.SID%TYPE;
BEGIN
SELECT SYS_CONTEXT ('userenv', 'ip_address')
INTO v_client_info
FROM DUAL;
DBMS_APPLICATION_INFO.set_client_info (v_client_info);
-- -- Get user SID information
-- SELECT SID
-- INTO v_sid
-- FROM v$mystat
-- WHERE ROWNUM
---- Get Program executable,OSUSER Details,Machine Details for this session
-- SELECT nvl(replace(client_info,'.','_'),'local')
-- INTO v_client_info
-- FROM v$session
-- WHERE SID = v_sid;
EXECUTE IMMEDIATE 'alter session set tracefile_identifier = ''' || REPLACE (NVL (v_client_info, 'local'), '.', '_') || '''';
END;
/
--实际上你还可以利用这段代码控制在回话级别设置cursor_sharing参数。
我在生产系统的例子:
CREATE OR REPLACE TRIGGER SYS.enable_para_cursor_sharing
AFTER LOGON ON DATABASE
DECLARE
v_exe v$session.program%TYPE;
v_sid v$session.SID%TYPE;
v_osuser v$session.osuser%TYPE;
v_machine v$session.machine%TYPE;
v_ok VARCHAR (10);
BEGIN
-- add and set clint_ip to application_info
DBMS_APPLICATION_INFO.set_client_info (SYS_CONTEXT ('userenv', 'ip_address'));
-- Get user SID information
SELECT SID
INTO v_sid
FROM v$mystat
WHERE ROWNUM
-- Get Program executable,OSUSER Details,Machine Details for this session
SELECT program, osuser, machine
INTO v_exe, v_osuser, v_machine
FROM v$session
WHERE SID = v_sid;
IF ( (USER = 'XXX' AND LOWER (v_exe) = 'aaa.exe')
OR (USER = 'YYY' AND LOWER (v_exe) = 'bbb.exe')
)
THEN
EXECUTE IMMEDIATE 'alter session set cursor_sharing =force';
--EXECUTE IMMEDIATE 'alter session set timed_statistics=true';
--EXECUTE IMMEDIATE 'alter session set max_dump_file_size=unlimited';
--EXECUTE IMMEDIATE 'alter session set tracefile_identifier=''session_trace_trigger''';
--EXECUTE IMMEDIATE 'alter session set events ‘’10046 trace name context forever, level 8'' ';
--DBMS_SESSION.set_identifier ('SQL TRACE ENABLED VIA LOGIN TRIGGER');
END IF;
END;
/
时间: 2024-10-23 18:21:13