在PL/SQL代码中或SQL*Plus命令行中均可以使用“SYS.DBMS_SYSTEM.KSDWRT”来实现向Oracle警告日志中写入信息的目的。1.进入到alert目录存放位置ora10g@asdlabdb01 /home/oracle$ cd $ORACLE_BASE/admin/$ORACLE_SID/bdump
2.查看警告日志中最后10行的信息
ora10g@asdlabdb01 /oracle/app/oracle/admin/ora10g/bdump$ tail -10 alert_ora10g.log
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=32, OS id=31597
Thu Dec 15 06:23:57 2010
Completed: ALTER DATABASE OPEN
Thu Dec 15 06:23:57 2010
db_recovery_file_dest_size of 4096 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
此处是为了对比写入前后信息的不同。
3.在SQL*Plus中实现向alert日志中写入信息的目的
ora10g@asdlabdb01 /oracle/app/oracle/admin/ora10g/bdump$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Dec 15 06:24:33 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
sys@ora10g> exec SYS.DBMS_SYSTEM.KSDWRT(2, 'Alert message writed by Secooler.');
PL/SQL procedure successfully completed.
sys@ora10g> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
4.查看alert日志中写入的内容
ora10g@asdlabdb01 /oracle/app/oracle/admin/ora10g/bdump$ tail -10 alert_ora10g.log
QMNC started with pid=32, OS id=31597
Thu Dec 15 06:23:57 2010
Completed: ALTER DATABASE OPEN
Thu Dec 15 06:23:57 2010
db_recovery_file_dest_size of 4096 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Thu Dec 15 06:24:39 2010
Alert message writed by Secooler.
可见alert日志中的最后两行记录了这条写入的信息(第一行表示写入的时间,第二行便是写入信息的内容)。
5.知识扩展
1)DBMS_SYSTEM的参数信息
sys@ora10g> desc SYS.DBMS_SYSTEM
……
PROCEDURE KSDWRT
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
DEST BINARY_INTEGER IN
TST VARCHAR2 IN
……
从参数信息上可以看到KSDWRT这个PROCEDURE有两个参数。第二个参数TST便是写入的信息内容;那么第一个参数都有几种可用的值呢?具体有如下三种可取的值:
“1”: Write to the standard trace file(向标准Trace文件中写入信息)
“2”: Write to the alert log(向alert日志文件中写入信息)
“3”: Write to both files at once(同时向Trace文件和alert日志文件中写入信息)
本例中我们用到了“2”这个选项实现的向alert日志文件中写入信息。
如果使用“1”或“3”,我们也可以实现向Trace文件中写入信息,该标准trace文件位于“$ORACLE_BASE/admin/$ORACLE_SID/udump”目录中。
--转自