LLI Wiki — My Digital Knowledge Base

Oracle: purge the listener log (listener.log)

Truncate, rotate or purge an oversized listener.log and old Oracle trace files.

The listener.log file grows without limit as long as listener logging is enabled. There are several ways to reduce it: truncate the file, turn logging off during the rotation, or automate the cleanup. For the file location, see Oracle listener log location and this page.

Solution 1: back up, empty and compress

In the listener trace directory:

cp listener.log listener_backup.log
cat /dev/null > listener.log
gzip listener_backup.log

The listener keeps writing to the emptied file.

Solution 2: turn logging off during the rotation

lsnrctl
LSNRCTL> show current_listener
LSNRCTL> set current_listener <listenername>
LSNRCTL> set log_status off

From another window, rename the file:

mv listener.log listener_backup.log

Then return to lsnrctl and turn logging back on:

LSNRCTL> set log_status on

Automate: trace cleanup script

This script deletes the trace and audit files older than 30 days. Adapt the paths to the instance:

#!/bin/bash
TODAY=$(date +"%Y%m%d")
find /u01/app/oracle/diag/rdbms/orcl/orcl/trace/*.trc -mtime +30 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/orcl/orcl/trace/*.trm -mtime +30 -exec rm {} \;
find /u01/app/oracle/admin/orcl/adump/*.aud -mtime +30 -exec rm {} \;
#mv /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log_$TODAY
#find /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log_* -mtime +30 -exec rm {} \;

Schedule the script with the crontab of the oracle user (su - oracle, then crontab -e):

00 23 * * * /home/user/scripts/cleaning_log.sh >> /home/user/scripts/cleaning_log.log 2>&1

Rotation with logrotate

Check the general configuration:

grep -r -- 'logrotate.conf' /etc/cron*

Example file in /etc/logrotate.d/ for the listener:

/u01/app/oracle/product/10.2.0/db_1/network/log/listener.log {
weekly
copytruncate
rotate 4
compress
}

Test the configuration, then check the rotation state:

logrotate -f /etc/logrotate.d/oracle-listener
cat /var/lib/logrotate.status

copytruncate copies the file and then truncates it in place: the listener does not need a restart.

Notes

Mastodon LLIMastodon SocialFosstodon