Alert Log DBA Oracle SQL

SQL Access to the alert log

I’m going to discuss how to get SQL access to your alert log in this entry. I will then build on that to make it even more useful in future posts.

Browsing the alert log can be convenient if you’re already on the server. However, it is often not possible or at least not overly convenient. You may find that as the developer DBA you do not have access to the production server, or you have to log in to many different servers to check all your alert logs. Since SQL is the main tool for DBAs and one of the most critical for developers of database driven applications, it would make sense to access the key log for database operations and issues via the same interface and be able to use your SQL tool of choice.

The way to be able to access the alert log with SQL is to define an external table for it. So I’ll use this need to write a little about how to create an external table for text file. It’s pretty easy and can often be very useful.

create directory bdump as '/path/to/bdump';
create user alertlog identified by alertlog;
alter user alertlog quota unlimited on users;
grant create session, resource to alertlog;
grant read,write on directory bdump to alertlog;

The directory path needs to be what you have “background_dump_dest” set to. You can look the current value up in v$parameter. To be able to do this with one script across databases, you’ll want to make this more dynamic with pl*sql such that the directory is retrieved from the database and used to build a dynamic DDL statement.

Now that we have a user with access to our bdump directory, we’ll create our alert_log table.

create table alert_log (text_line varchar2(255))
organization external
(type oracle_loader
 default directory bdump
 location ('alert_ORCL.log'));

This is a minimal create external table statement. There are many more options to use, but we’ll leave those alone in this blog post.

The create table statement is pretty straight forward, here’s what it will do:

  • Creates a table with data that is located external to the database
  • Take all data in each line into the column text_line
  • Use the normal oracle_loader (SQL*Loader) driver to access the data
  • It uses the bdump directory object to specify where the alert log file is located.
  • Get data from the file alert_ORCL.log.

That is all it takes. We can now access this table with SQL and use our normal techniques for filtering and aggregating information.

To look at the snapshot too old messages we generated in a previous blog post, we’d use this statement:

select text_line
  from alert_log
 where text_line like '%ORA-01555%';

Leave a Comment

Your email address will not be published. Required fields are marked *

*