Exforsys

Home arrow Reviews arrow Oracle Database Management Utilities

Oracle Utilities - Extending the alert.log Analysis

Author: Packt Publishing     Published on: 4th Jan 2010

Extending the alert.log analysis with External Tables

Reading the alert.log from the database is a useful feature which can help you to find any outstanding error messages reported in this file.

 

Ads

Sample Code
  1.  
  2.       create table ALERT_LOG(
  3.            text_line       varchar2(512)
  4.       )
  5.         organization external (
  6.            type ORACLE_LOADER
  7.            default directory BACKGROUND_DUMP_DEST
  8.            access parameters(
  9.                    records delimited by newline
  10.                    nobadfile
  11.                    nodiscardfile
  12.                    nologfile
  13.            )
  14.            location( 'alert_beta.log')
  15.         )
  16.  
Copyright exforsys.com


Once the External Table has been created, the alert.log file can be queried just like any other regular table.

Sample Code
  1.  
  2. SQL> select text_line from alert_log
  3.   2    where text_line like 'ORA-%'
  4.  
  5. TEXT_LINE
  6. -------------------------------------------------------------------------
  7. -------
  8. ORA-1109 signalled during: ALTER DATABASE CLOSE NORMAL...
  9. ORA-00313: open failed for members of log group 1 of thread 1
  10. ORA-00312: online log 1 thread 1: '/u01/oracle/oradata/beta/redo01.log'
  11. ORA-27037: unable to obtain file status
  12. ORA-00313: open failed for members of log group 2 of thread 1
  13. ORA-00312: online log 2 thread 1: '/u01/oracle/oradata/beta/redo02.log'
  14. ORA-27037: unable to obtain file status
  15. ORA-00313: open failed for members of log group 3 of thread 1
  16. ORA-00312: online log 3 thread 1: '/u01/oracle/oradata/beta/redo03.log'
  17. ORA-27037: unable to obtain file status
  18.  
Copyright exforsys.com


Querying the alert.log file up to this phase is useful just to see the contents of the file and look for basic ORA-% strings. This could also be achieved by using the alert.log link in the Enterprise Manager (EM).

The alert.log file can be queried by means of the EM, but as this can only be viewed from the EM in an interactive mode, you can only rely on the preset alerts.

If further automatic work needs to be done, then it is useful to do some more work with the alert analysis tool. A temporary table can be used to store the contents of the ALERT_LOG table, along with an extra TIMESTAMP column, so it can be queried in detail in an EM-like manner.

Sample Code
  1.  
  2.     create global temporary table TMP_ALERT_LOG (
  3.        LINE_NO         NUMBER(6),
  4.        TIMESTAMP       DATE,
  5.        TEXT_LINE       VARCHAR2(512)
  6.     )
  7.     on commit preserve rows
  8.  
Copyright exforsys.com


A bit of PLSQL programming is necessary so the ALERT_LOG file can be modified and inserted into the TMP_ALERT_LOG, (enabling further queries can be done).

Sample Code
  1.  
  2.     declare
  3.     cursor
  4.       alertLogCur is
  5.       select ROWNUM, TEXT_LINE
  6.       from    ALERT_LOG
  7.     currentDate      date
  8.     altertLogRec     ALERT_LOG.TEXT_LINE%TYPE
  9.     testDay          varchar2(10)
  10.     begin
  11.     currentDate := sysdate
  12.     for alertLogInst in alertLogCur loop
  13.       -- fetch row and determine if this is a date row
  14.       testDay := substr(alertLogInst.text_line, 1, 3)
  15.       if testDay = 'Sun' or
  16.         testDay = 'Mon' or
  17.         testDay = 'Tue' or
  18.         testDay = 'Wed' or
  19.         testDay = 'Thu' or
  20.         testDay = 'Fri' or
  21.         testDay = 'Sat'
  22.       then
  23.         -- if this is a date row, it sets the current logical record date
  24.         currentDate := to_date( alertlogInst.text_line, 'Dy Mon DD HH24:
  25.          MI:SS YYYY')
  26.       end if
  27.       insert into TMP_ALERT_LOG
  28.       values(
  29.          alertLogInst.rownum,
  30.          currentDate,
  31.          alertLogInst.text_line
  32.       )
  33.     end loop
  34.     end
  35.     /
  36.  
Copyright exforsys.com


As the contents of the alert.log end up in a temporary table, more than one DBA can query it at the same time, or restrict the DBA's accessibilities. There is no need to manage the purge and maintenance of the table after the session has ended, it can be indexed and there is little overhead by means of this procedure. More over, as this is a temporary object, minimum redo log information is generated.

Once the external ALERT_LOG and the temporary ALERT_LOG tables have been created, it is possible to perform, not only filters by date (provided by Enterprise Manager) but also any query against the alert.log file.

Sample Code
  1.  
  2.     SELECT TIMESTAMP, TEXT_LINE
  3.     FROM TMP_ALERT_LOG
  4.     WHERE TIMESTAMP IN (
  5.        SELECT TIMESTAMP
  6.        FROM TMP_ALERT_LOG
  7.        WHERE TEXT_LINE LIKE 'ORA-%'
  8.     )
  9.     AND TIMESTAMP BETWEEN SYSDATE-30 AND SYSDATE
  10.     ORDER BY LINE_NO
  11.  
Copyright exforsys.com


Further treatment can be done on this concept to look for specific error messages, analyze specific time frames and perform drill down analysis.

 

Ads

This procedure can be extended to read the trace files or any other text file from the database. v



 
This tutorial is part of a Oracle Database Management Utilities tutorial series. Read it from the beginning and learn yourself.

Oracle Database Management Utilities

 

Comments