How to Trim Alert Log File in Oracle

  • by

The retention of alert log cannot be controlled by ADRCI utility, it needs manual intervention. In this post, I'd like to share how I reduce the size of alert log by means of trimming the content of alert log file in order to save disk space.

Clear Alert Log

Whenever you want to clear alert log in a hurry, you can empty all content of alert log in this way:

[oracle@test ~]$ cat /dev/null > /path/to/alert_ORCL.log

This approach is pretty fast to solve your space problem if you have no time to think over a better solution.

Deleting the alert log directly is also a way to do it as long as no one locks the file, the database will create a new same name file for the alert log afterwards.

Please note that, the location of alert log may not easily be found, you need to know where to find Oracle alert log location.

Trim Alert Log

If you want to keep most recent entries in the alert log just like trimming obsolete records off the alert log file, you may play this trick.

Here are the steps:

  1. Paste the last certain number of lines of the alert log onto a second file which is temporary and transitional in the first command. In this example, we keep 50000 lines.
  2. [oracle@test ~]$ tail -50000 /path/to/alert_ORCL.log > /path/to/alert_ORCL.log.copy
  3. Copy the transitional file back to the alert log with force option.
  4. [oracle@test ~]$ cp -f /path/to/alert_ORCL.log.copy /path/to/alert_ORCL.log
  5. Empty the transitional file in order to free its space if the space is still sensitive.
  6. [oracle@test ~]$ cat /dev/null > /path/to/alert_ORCL.log.copy

For convenience, I concatenate all commands in one line for executing them without any gaps. This could also reduce the loss of log entries between executions.

[oracle@test ~]$ tail -50000 /path/to/alert_ORCL.log > /path/to/alert_ORCL.log.copy; cp -f /path/to/alert_ORCL.log.copy /path/to/alert_ORCL.log; cat /dev/null > /path/to/alert_ORCL.log.copy

Of course, you can wrap these commands in a shell script and schedule it for regularlly purging.

With respect to alert log in rdbms, you have to handle listener.log in listener with the same manner as well.

Even though 50000 lines that we kept in the alert log sounds large in quantity, the text file is not so big in size.

For rest of other files, there's an integrated way to delete all trace logs, audit files and the alert log.

Leave a Reply

Your email address will not be published. Required fields are marked *