Oracle Tips : How to write message into Alert.log
Oracle Tips : How to write message into Alert.log
ตอนนี้ 0.10am อรุณสวัสดิ์ครับ พอดียังไม่เข้านอนนั่งทำงานอยู่ แล้วก็เจอเว็บนึงบอกวิธีการเขียนข้อความลอง loracle log files, ก็เลยมาทดลองเล่นดู พบว่าใช้งานได้จริงเลยกะเอามาแบ่งปันกัน
วิธีการนี้สามารถเขียนข้อความลงได้ทั้ง
1. $ORACLE_BASE/admin/<sid>/bdump/alert_<sid>.log
2. $ORACLE_BASE/admin/<sid>/udump/<sid>_ora_xxx.trc
โดยเราจะเรียกใช้ package “DBMS_SYSTEM” ซึ่งมี procedure มากมายที่น่าสนใจ วันนี้จะหยิบมาเฉพาะ procedure ที่ใช้เขียนลงไฟล์ คือ “KSDWRT” มี syntax ดังนี้
dbms_system.ksdwrt (mode IN BINARY_INTEGER, Message IN VARCHAR2);
mode =1: Write to the standard trace file
mode =2: Write to the alert log
mode =3: Write to both files at once
สำหรับการเรียกใช้ package นี้จะเรียกใช้ได้เฉพาะ sysdba ดังนั้นถ้าจะให้ user อื่นใช้ได้จะมีขั้นตอนดังนี้
1. login as sysdba
2. grant execute on dbms_system to <user1>;
3. login as <user1>
4. execute as example:
SQL> exec sys.dbms_system.ksdwrt(3,’ORA-TEST3: write to alert_log and Trace Files’);
PL/SQL procedure successfully completed.
เท่านี้เราก็จะมีข้อความ “ORA-TEST3: write to alert_log and Trace Files” ทั้ง alert.log และ trace file ดังนี้
Alert.log |
Sun Jun 28 00:22:30 2009 ORA-TEST3: write to alert_log and Trace Files |
Trace file |
…Windows thread id: 4356, image: oracle.exe (SHAD)
*** ACTION NAME:() 2009-06-28 00:05:30.734 *** MODULE NAME:(SQL*Plus) 2009-06-28 00:05:30.734 *** SERVICE NAME:(SYS$USERS) 2009-06-28 00:05:30.734 *** SESSION ID:(139.10) 2009-06-28 00:05:30.734 *** 2009-06-28 00:22:30.312 ORA-TEST3: write to alert_log and Trace Files
|