Quantcast
Channel: Oracle
Viewing all articles
Browse latest Browse all 1814

Blog Post: Logfile Housekeeping

$
0
0
There are tons of scripts and various scheduler jobs out in the field to get rid of old logfiles, dumps and traces. Some of them simply use the find command while others are using the ADR command line interface (adrci). There is nothing wrong with those scripts and some of them are still required but for traces and dumps there is a far easier way. With Oracle 11g the new Automatic Diagnostic Repository has been introduced. This tool nmerges the various logs, traces, dumps, etc. into one central directory structure and allows to create incident packages (IPS = Incident Package Service) composed of traces and logs. Via the command line interface you can also have a look into the alert-file or other traces without the need to change to the corresponding directory, which is due to the new directory layout being somewhat cumbersome. Example: C:\Users\Johannes>adrci adrci> set home diag\rdbms\herbert\herbert adrci> show alert -tail -f 2016-07-28 11:05:26.503000 +02:00 Warning: VKTM detected a time drift. Time drifts can result in an unexpected behavior such as time-outs. Please check trace file for more details. 2016-07-28 11:45:42.436000 +02:00 ... 2016-07-29 10:00:04.340000 +02:00 Thread 1 advanced to log sequence 423 (LGWR switch) Current log# 3 seq# 423 mem# 0: D:\ORADATA\HERBERT\REDO03.LOG Archived Log entry 85 added for thread 1 sequence 422 ID 0x452b04c5 dest 1: This is the alert file of the database HERBERT running on a Microsoft windows server. But even better: it uses the tail -f command to continuously read the alert-file. With adrci some housekeeping has been implemented. Using the purge command you can easily remove all (or some) logs, traces or dumps without the need to use the Unix find command (or a similar one at Microsoft Windows). Example: adrci> purge -age 129600 This command purges all diagnostic files (alert, incident, trace, cdump, hm, utscdmp) older than 129600 Minutes (!). I don't have a clue why Oracle implemented the value as minutes but that's how it is. So in a first step you could use this command to purge the data. But Oracle already implemented some housekeeping: Traces, Dumps and IPS files are purged after 30 days (SHORTP_POLICY=720) while alert-files and incidents are kept for one year (LONGP_POLICY=8760). With some easy math you calculate that Oracle is using hours instead of minutes ... So the easiest way to get rid of all kind of diagnostic files is to simply change those values accordingly. 30 days for traces sounds reasonable to me so I'm only interested in the LONGP_POLICY. In most environments I change this to 90 days = 2160 (hours). Example: adrci> set control (LONGP_POLICY=2160) adrci> show control ADR Home = D:\app\oracle\diag\rdbms\herbert\herbert: ************************************************************************* ADRID SHORTP_POLICY LONGP_POLICY LAST_MOD_TIME LAST_AUTOPRG_TIME LAST_MANUPRG_TIME ADRDIR_VERSION ADRSCHM_VERSION ADRSCHMV_SUMMARY ADRALERT_VERSION CREATE_TIME -------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ---------------------------------------- 3455421390 720 2160 2016-07-29 16:21:55.111000 +02:00 2016-07-29 11:02:57.441000 +02:00 2016-07-29 16:14:44.466000 +02:00 1 2 82 1 2015-10-29 10:03:40.075000 +01:00 1 rows fetched There is no need to create any cron or other scheduler job but all traces, etc. are now removed after 90 days latest. But what about our alert-file? Unfortunately only the xml-files in the diagnostic directory alert are automatically purged. The good old alert .log will not be touched. Same for the listener.log. So if you want to have some housekeeping for those files as well a manual approach is still required. As an example I created a small shell script which makes a copy of the current alert .log with the current timestamp and purges data older than 30 days from the original file. Please don't move the alert-file around as the Oracle kernel stays with the original inode (and not with the filename) unless you restart the database instance. Example: TIMESTAMP='date +"%y%m%d_%H%M%S"' DAYS=50 TODAY=`date` LOGFILE=adrci_'hostname -s'_${TIMESTAMP}.log LINENR=1 for ALERTFILE in 'find /u01/app/oracle/diag -name alert*.log -print' do ALERTOLD='dirname $ALERTFILE'/'basename ${ALERTFILE}'_${TIMESTAMP} cp $ALERTFILE $ALERTOLD DELETEDATE="$(date +"%a %b %d" -d "$TODAY" -d "$DAYS days ago")" echo "cp $ALERTFILE $ALERTOLD" echo "Delete until $DELETEDATE" LINENR='fgrep -n -m 1 "$DELETEDATE" $ALERTFILE | cut -d":" -f 1' if [ -n "${LINENR}" ] then sed -i "1,${LINENR}d" $ALERTFILE fi done There might be ways to simplify the script - but it works! Like with the alert-file the listener.log is not touched as well. But in this case you can simply mv the file around or if you do not expect network problems you might want to switch off the logging. Example: lsnrctl LSNRCTL> show log_status Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER))) LISTENER parameter "log_status" set to ON The command completed successfully LSNRCTL> set log_status off Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER))) LISTENER parameter "log_status" set to OFF The command completed successfully That's it!

Viewing all articles
Browse latest Browse all 1814

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>