Oracle 11.2 Managing Alert log and Trc files

>> Tuesday, 29 May 2012

Oracle now want you to use adrci to manage the alert log and trace files.

It's worth getting to grips with too, but it's also worth knowing that adrci doesn't actually control the alert_${ORACLE_SID}.log.  It will control the xml logs and the .trc files but the .log is still your own problem!

Put this as part of a shell script to look after your Alert xmls, incidents, trace files, core dumps and health monitor data and reports (remember them)

###
##adrci purge -age in_minutes -type ALERT
## 6 months = 267840, 3 months = 129600
export ORACLE_HOME=/set/my/path/if/it/wasn't/already
echo INFO: adrci purge started at `date +%D-%T`
$ORACLE_HOME/bin/adrci exec="show homes"|grep -v : | grep -v tnslsnr | while read file_line
do
echo INFO: adrci purging diagnostic destination $file_line
echo INFO: purging ALERT xml
$ORACLE_HOME/bin/adrci exec="set homepath $file_line;purge -age 267840 -type ALERT"
echo INFO: purging INCIDENT
$ORACLE_HOME/bin/adrci exec="set homepath $file_line;purge -age 129600 -type INCIDENT"
echo INFO: purging TRACE
$ORACLE_HOME/bin/adrci exec="set homepath $file_line;purge -age 129600 -type TRACE"
echo INFO: purging CDUMP
$ORACLE_HOME/bin/adrci exec="set homepath $file_line;purge -age 129600 -type CDUMP"
echo INFO: purging HM
$ORACLE_HOME/bin/adrci exec="set homepath $file_line;purge -age 129600 -type HM"
done
###

This will look after your logs by rolling them each time the script is run:

#### BEGIN
## alert log text file
export ORACLE_HOME=/set/my/path/if/it/wasn't/already
export ORACLE_SID=MYSID
$ORACLE_HOME/bin/sqlplus -s / as sysdba << EOF | tee /tmp/diagdest
set echo off;
SET SERVEROUTPUT ON;
set heading off;
select value from v\$diag_info where name='Diag Trace';
exit
EOF
diagdest=`cat /tmp/diagdest`

ALERT_LOG_PATH=$diagdest

if [ -f ${ALERT_LOG_PATH}/alert_log_trim ]
then
echo "alert log ${ALERT_LOG} already being trimmed don't try to do it again it really messes things up"
###I have a function here that sends the error off to my alerting system you could just exit 1
exit 1
fi

touch ${ALERT_LOG_PATH}/alert_log_trim

ALERT_LOG=${ALERT_LOG_PATH}/alert_${ORACLE_SID}.log
echo ALERT_LOG=$ALERT_LOG

if [ ! -f ${ALERT_LOG} ]
then echo "alert log does not exist error "
rm ${ALERT_LOG_PATH}/alert_log_trim
###I have a function here that sends the error off to my alerting system  you could just exit 1
exit 1
fi

ls -l ${ALERT_LOG}*
## Roll the text based alert logs, remember adrci ony deals with the xml version of the log
### if you ran this once a month you'd have 3 months worth stored away
cp -p ${ALERT_LOG}.old3 ${ALERT_LOG}.old4
cp -p ${ALERT_LOG}.old2 ${ALERT_LOG}.old3
cp -p ${ALERT_LOG}.old1 ${ALERT_LOG}.old2
cp -p ${ALERT_LOG} ${ALERT_LOG}.old1

cd ${ALERT_LOG_PATH}
echo "cat /dev/null > alert_${ORACLE_SID}.log"
cat /dev/null > alert_${ORACLE_SID}.log

ls -l ${ALERT_LOG}*
rm ${ALERT_LOG_PATH}/alert_log_trim

###### END


You need to slot this 2 extracts into a proper shell script with appropriate error reporting etc.


I then cron my script to run on the first Wednesday of every month:
(I don't want to do it by date as it would sometimes run on the weekends.  So by choosing a weekday, if it errors for any reason , I'm probably going to be at work already - unless it's Christmas, I know!)

00 10 * * 3 [ `date +\%d` -le 7 ] && /pth/to/my/script/myscriptname 2>&1

Good Luck, Enjoy!

(I'm sure when I first started to try and get to grips with this I took the adrci putge lines from another blog, but now I have no idea where. If you spot the lines as character for character yours, then thank you for sharing them originally, poimt it out to me and I'll link back to you.)

0 comments:


  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP