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.

Clear Alert Log

Whenever you want to clear alert log in a hurry or the space problem becomes serious, you can empty all content of alert log in this way:

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

This command can solve your space problem in a second if you have no time to think over a better solution. Just don't forget to change the location of alert log.

Deleting the alert log directly is also a way to do it as long as no one locks the file at that moment, the database will create a new file for the alert log afterwards. However, emptying is my first choice.

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 temporary and 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. Additionally, 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 may have to handle listener.log in listener with the same manner as well, but first, you need to know the location of listener before preparing your script.

By the way, even though 50000 lines that we keep in the alert log sounds large in quantity, the text file is not so big in size as you thought.

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 *