使用SYS.DBMS_SYSTEM.KSDWRT向Oracle实现向警告日志中写入信息 _MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 1921 | 回复: 0   主题: 使用SYS.DBMS_SYSTEM.KSDWRT向Oracle实现向警告日志中写入信息         下一篇 
shunli
注册用户
等级:新兵
经验:36
发帖:59
精华:0
注册:2011-9-23
状态:离线
发送短消息息给shunli 加好友    发送短消息息给shunli 发消息
发表于: IP:您无权察看 2015-6-25 11:16:55 | [全部帖] [楼主帖] 楼主

在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”目录中。

--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论