An sql interface for alert log

>>Script Language and Platform: Oracle
This is a very handy utility (9i only) which let you query the alert log file from an sql tool (sqlplus/toad /oem …).

It’s a generic one (unix,windows,vms) , and it’s very simple to install . (install which dba owner).

Author: Amihay Gonen


GRANT CREATE ANY DIRECTORY TO …;

DECLARE
a number ;
b varchar2(2000);
begin

a:=dbms_utility.get_parameter_value(parnam => ‘background_dump_dest’,intval => a,strval => b);
BEGIN
execute immediate ‘CREATE OR REPLACE DIRECTORY VIRTUAL_BDUMP_DIR as ”’||b||””;
EXCEPTION when others THEN null; END;
END;
/

CREATE OR REPLACE PACKAGE
alert_log_analyzer
AS

type alert_rec is record
(
v_date date,
v_text varchar2(4000)
);

type alert_rec_tab is table of alert_rec;

function read return alert_rec_tab
pipelined;

END alert_log_analyzer;
/
CREATE OR REPLACE PACKAGE BODY
alert_log_analyzer
AS

— constants
VIRTUAL_BDUMP_DIR constant varchar2(100) := ‘VIRTUAL_BDUMP_DIR’;
timestamp_format constant varchar2(100) := ‘YYYYMMDD’;

function get_parameter_value(p_name varchar2 ) return varchar2 is
intval binary_integer;
strval varchar2(2000);
begin
if dbms_utility.get_parameter_value(parnam => p_name,intval => intval,strval => strval) = 1 then
return strval;
else
return intval;
end if;
end;

function read return alert_rec_tab
pipelined
is
v_alert_rec alert_rec;
infile bfile;
r_char10 RAW(4);
char10 VARCHAR2(1) := CHR(10);
v_length INTEGER;
buffer VARCHAR2(2000);
pointa INTEGER:=1;
pointb INTEGER;
next_date date;

begin
infile:=BFILENAME(virtual_bdump_dir,’alert_’||get_parameter_value(‘db_name’)||’.log’);
DBMS_LOB.FILEOPEN(infile,DBMS_LOB.FILE_READONLY);
r_char10 := UTL_RAW.CAST_TO_RAW(char10);

if infile is null then return ; end if ;

LOOP
pointb := DBMS_LOB.INSTR(infile,r_char10,pointa,1);
EXIT WHEN pointb = 0;
v_length := pointb – pointa+1;
buffer:= utl_raw.cast_to_varchar2(DBMS_LOB.SUBSTR(infile,v_length,pointa));
begin
next_date := to_date(buffer,’Dy Mon dd hh24:mi:ss yyyy’);
— we have found date , clear buffer and pipe row
pipe row(v_alert_rec);
v_alert_rec.v_text:= null;
v_alert_rec.v_date:=next_date;
exception when others then
— it’s is not a date put next row in buffer
v_alert_rec.v_text:= v_alert_rec.v_text || buffer;
pointa := pointb + 1;
end;
pointa := pointb + 1;
END LOOP;

pipe row(v_alert_rec);
DBMS_LOB.FILECLOSE(infile);

end;

END alert_log_analyzer;
/

SELECT * FROM TABLE(alert_log_analyzer.read);



Disclaimer:
We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
“as -is”, without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose…

Disclaimer Continued

Back to Database Journal Home

Latest Articles