Showing posts with label Monitoring. Show all posts
Showing posts with label Monitoring. Show all posts

Thursday, June 13, 2013

Writing user defined message to Alert Log in Oracle.

In Oracle , there is a undocumented package/API ( dbms_system) to write user defined messages in the alert log.  This can be executed an user with SYSDBA privilege . You may want to use this with caution , as it is not supported by Oracle.

The signature of this procedure call is

dbms_system.ksdwrt ( Trace Identifier , User Defined Message )

Note :
When Trace Identifier is 1 , the message is written to a trace file only.
When Trace Identifier is 2 , the message is written to a alert log only.
When Trace Identifier is 3 , the message is written to a alert log and trace file. 


Here is an example.


SQL> show parameter user_dump_de

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest                       string      C:\app\mohideen\diag\rdbms\zmdb
                                                 rd11\zmdbrd11\trace



SQL> exec dbms_system.ksdwrt(1, 'Writing Alert message with 1');

PL/SQL procedure successfully completed.

SQL> exec dbms_system.ksdwrt(2, 'Writing Alert message with 2');

PL/SQL procedure successfully completed.

SQL> exec dbms_system.ksdwrt(3, 'Writing Alert message with 3');

PL/SQL procedure successfully completed.



C:\app\mohideen\diag\rdbms\zmdbrd11\zmdbrd11\trace>type alert_zmdbrd11.log
Thu Jun 13 15:31:44 2013
Writing Alert message with 2
Writing Alert message with 3



C:\app\mohideen\diag\rdbms\zmdbrd11\zmdbrd11\trace>type zmdbrd11_ora_8928.trc
Trace file C:\APP\MOHIDEEN\diag\rdbms\zmdbrd11\zmdbrd11\trace\zmdbrd11_ora_8928.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
Windows NT Version V6.1 Service Pack 1
CPU                 : 8 - type 8664, 8 Physical Cores
Process Affinity    : 0x0x0000000000000000
Memory (Avail/Total): Ph:4194M/12285M, Ph+PgF:14916M/24569M
Instance name: zmdbrd11
Redo thread mounted by this instance: 1
Oracle process number: 20
Windows thread id: 8928, image: ORACLE.EXE (SHAD)


*** 2013-06-13 15:31:38.973
*** SESSION ID:(131.1077) 2013-06-13 15:31:38.973
*** CLIENT ID:() 2013-06-13 15:31:38.973
*** SERVICE NAME:(SYS$USERS) 2013-06-13 15:31:38.973
*** MODULE NAME:(sqlplus.exe) 2013-06-13 15:31:38.973
*** ACTION NAME:() 2013-06-13 15:31:38.973

Writing Alert message with 1

*** 2013-06-13 15:31:52.171
Writing Alert message with 3


At times , this trick could be useful . You can see my another post on how to monitor the alert log (
http://mfzahirdba.blogspot.com/2010/10/monitoring-alert-log.html) .

Comments Welcome.

Tuesday, October 5, 2010

Monitoring Alert Log

Monitoring Alert Log has become lot easier with Oracle 11g . In Oracle 11g , the contents of the alert log are exposed via fixed table . 

Also , in  Oracle 11g , the alert log is also stored in xml format . You can ADRCI to view / purge the contents . For ADRCI , please see one of my post here ( http://mfzahirdba.blogspot.com/2010/05/health-check.html)

Prior to this release , you can construct an external table poiniting to alert log . For this approach , please refer to chapter 3 of Tom Kyte's Expert Oracle book .

Let us returned to using fixed table ( it does not seems to be documented ) . Alert log is exposed as "X$DBGALERTEXT".

Let us create a view , so that we can grant access to non sys users.

SQL> CREATE OR REPLACE VIEW SYS.ALERT_LOG_v
2 AS
3 SELECT * FROM X$DBGALERTEXT;



View created.

SQL> grant select on SYS.ALERT_LOG_v to scott ;

Grant succeeded.

SQL> conn scott/tiger



Connected.


SQL> desc sys.alert_log_v


Name Null?                                Type

----------------------------------------- -------- ----------------------------

ADDR                                      RAW(8)
INDX                                      NUMBER
INST_ID                                   NUMBER
ORIGINATING_TIMESTAMP                     TIMESTAMP(3) WITH TIME ZONE
NORMALIZED_TIMESTAMP                      TIMESTAMP(3) WITH TIME ZONE
ORGANIZATION_ID                           VARCHAR2(64)
COMPONENT_ID                              VARCHAR2(64)
HOST_ID                                   VARCHAR2(64)
HOST_ADDRESS                              VARCHAR2(46)
MESSAGE_TYPE                              NUMBER
MESSAGE_LEVEL                             NUMBER
MESSAGE_ID                                VARCHAR2(64)
MESSAGE_GROUP                             VARCHAR2(64)
CLIENT_ID                                 VARCHAR2(64)
MODULE_ID                                 VARCHAR2(64)
PROCESS_ID                                VARCHAR2(32)
THREAD_ID                                 VARCHAR2(64)
USER_ID                                   VARCHAR2(64)
INSTANCE_ID                               VARCHAR2(64)
DETAILED_LOCATION                         VARCHAR2(160)
PROBLEM_KEY                               VARCHAR2(64)
UPSTREAM_COMP_ID                          VARCHAR2(100)

....
.....
 
I can issue the following query  ( in a recurring job ) to see if there are lot of "ORA-" errors in the last 15 minutes .
 
SQL> SELECT message_text ,

2 client_id ,
3 originating_timestamp
4 FROM sys.alert_log_v
5 WHERE originating_timestamp >= sysdate-(1/24/60)*15
6 AND message_text LIKE '%%ORA-%%';


no rows selected


Monitoring Alert Log is made easier with this approach .