Here are detailed instructions on how to configure your database in order to get every 'ORA-'-error from the alert.log to your email address or mobile phone as an SMS message. I have tested all that with 8i and 9i databases and it works fine. Probably my solution is not the optimal one, so all suggestions for improvement are more than wellcome.
Step 1. If JVM (Java Virtual Machine) has been already installed go to Step 2.
If not, then we consider the two cases: 8i and 9i. If you run 8i, then as internal run (d:\oracle\ora81 is my Oracle home directory, you will have to replace that with yours):
Step 4. In init.ora, set UTL_FILE_DIR to the directory where alert.log resides, set JOB_QUEUE_PROCESSESS to a some value (depending on how many jobs you have, often 10 is OK) and set JOB_QUEUE_INTERVAL to 60. Now, bounce the instance.
Note that in 9i, JOB_QUEUE_INTERVAL is obsolete!
Step 5. We will use a table called alert_historia, where the rows of the alert.log will be stored. I decided to implement that in order to know which line from the alert.log was last read. We use Patrol, which has the bug that it reads the alert.log always from the beginning. Well, we don't want the same ORA- line sent to us all the time until we delete the alert.log, do we :-)
Run in SQL*Plus:
CREATE SEQUENCE alert_seq
INCREMENT BY 1
START WITH 1
CREATE TABLE alert_historia
lid NUMBER NOT NULL,
dtpvm DATE NOT NULL,
ALTER TABLE alert_historia
ADD CONSTRAINT pk_alert PRIMARY KEY (lid)
Step 6. Create the following procedure which will read the alert.log. Replace
'c:\oracle9i\admin\JM9\bdump' with you BDUMP directory.
PROCEDURE read_file(P_NAME in varchar2) AS
k PLS_INTEGER := 0;
name := P_NAME;
select count(*) into MAX_LID from ALERT_HISTORIA;
id := UTL_FILE.FOPEN('c:\oracle9i\admin\JM9\bdump',name,'r');
UTL_FILE.GET_LINE(id,filedata); k := k+1;
if k > max_lid then
insert into alert_historia values(alert_seq.nextval,filedata,sysdate,null);
if instr(filedata,'ORA-') > 0 then
send_email('< firstname.lastname@example.org >','< email@example.com >','JD9 ERROR',filedata);
-- This line is meant for SMS messages. Anything sent to julian@GSM.net will
-- be forwared to my mobile phone. Almost all operators in the world offer such
-- email address to their clients:
-- send_email('< firstname.lastname@example.org >','< julian@GSM.net >','JD9 error:',filedata);
WHEN NO_DATA_FOUND THEN EXIT;
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND');
WHEN UTL_FILE.INVALID_PATH THEN
WHEN UTL_FILE.READ_ERROR THEN
WHEN UTL_FILE.WRITE_ERROR THEN
WHEN OTHERS THEN
err := SQLERRM;
num := SQLCODE;
DBMS_OUTPUT.PUT_LINE('Error trying to read file');
Step 6. Decide on how often you want Oracle to wake up to check for errors in the alert.log. For every 90 seconds run in SQL*Plus:
variable jobno number;
You can verify the job with select * from dba_jobs;
Note: Replace above ALERT.LOG with the name of your alert.log. It might not be ALERT.LOG.
Done. After 90 seconds you should have in ALERT_HISTORIA the rows from the alert.log:
SQL> col alert_rivi for A77
SQL> col remark for A30
SQL> select * from alert_historia;
You should also get all errors from the alert.log via email or straight to you mobile phone at that moment. If you delete your alert.log, you should truncate alert_historia at the same moment, remember this!
Final remark: In the procedure read_file, there is a commented line meant for SMS messages. If you want to use SMS, not email, then comment out the previous email line and use the SMS line. In that procedure, anything sent to julian@GSM.net will be forwared to my mobile phone. As almost all operators in the world offer such email address to their clients, you should register that service with your GSM operator. In Finland, I did that in Internet in a couple of minutes. I just had to type in my GSM number, a got back an activation code as an SMS message, then I entered that code and chose my email address at that operator. Usually, it is
by default email@example.com, where 123456789 is your GSM number.
Comments and complains to firstname.lastname@example.org :-)
[Edited by julian on 05-14-2002 at 03:59 AM]
05-14-2002, 03:46 AM
Very well written, a good candidate for the HOW TO forum.
05-14-2002, 03:59 AM
It was expected from you.
05-14-2002, 04:30 AM
If you are using Oracle Enterprise Manager (OEM) this is all built in.
Register the "Alert" event against your database(s) and the OMS will be notified of any new errors in the alert log.
If you want these errors to be sent to you via email or a pager simply add your SMTP server details to the "Configure Paging/Email" dialog:
Configuration -> Configure Paging/Email
You can adjust the content of the mail by updating the settings in the following dialog:
Configuration -> Preferences -> Notification Tab
I always use this and I've had no problems so far.
05-14-2002, 04:40 AM
other option is stored your alert file in database and run query against it
05-14-2002, 04:50 AM
I've used DIY$ views to query the alert log before:
I was unaware there was an option to have it written directly to the database. How do you do it? Or are you just loading it in after it's been written?
05-14-2002, 05:19 AM
create global temporary table alert_log
( line int primary key,
on commit preserve rows
create or replace procedure load_alert
l_start number := dbms_utility.get_time;
select a.value, 'alert_' || b.instance || '.log'
into l_background_dump_dest, l_filename
from v$parameter a, v$thread b
where a.name = 'background_dump_dest';
'create or replace directory x$alert_log$x as
''' || l_background_dump_dest || '''';