---
title: Log rotation for Oracle database
description: Most of you may already know how to configure the log rotation for your database alert log or the listener log etc,. As root, you can manually create a con
---

[Blog | Pythian ](https://www.pythian.com/blog)

# [Log rotation for Oracle database](https://www.pythian.com/blog/log-rotation-oracle-database)

 Written by [Howie Jiang](https://www.pythian.com/blog/author/howie-jiang) | Jan 11, 2018 5:00:00 AM

Most of you may already know how to configure the log rotation for your database alert log or the listener log etc,. As root, you can manually create a configuration file as below, and put it into /etc/logrotate.d/.

> ```
> /u01/app/oracle/diag/rdbms/test1/TEST1/trace/alert_TEST1.log
>  {
>   daily
>   rotate 15
>   compress
>   copytruncate
>   delaycompress
>   create 0640 oracle dba
>   notifempty
>  }
>  
> ```

It's easy to create the log rotation configuration file for one database. But what if you have 20+ databases running on your server, are you still planning to manually locate their alert log files? Today I would like to introduce a shell script that will automatically search the running ASM instance, databases and listeners and create the configuration files for you. Here are the steps on how to run shell scripts. 1.

## Automated configuration steps

1. Run the shell script

> ```
> [oracle@testserver ~]$ ./gen_logrotate_config.sh
>  
> ```

 2. Three configuration files will be created: oracle_rdbms_log, oracle_asm_log and oracle_listener_log. Let's say we have 4 running databases: TEST1, TEST2, TEST3 and TEST4, one ASM instance +ASM1, three listeners: listener_scan1, listener_scan2 and LISTENER. The configuration files will be like:

> ```
> [oracle@testserver ~]$ cat oracle_rdbms_log
>  /u01/app/oracle/diag/rdbms/test1/TEST1/trace/alert_TEST1.log /u01/app/oracle/diag/rdbms/test2/TEST2/trace/alert_TEST2.log /u01/app/oracle/diag/rdbms/test3/TEST3/trace/alert_TEST3.log /u01/app/oracle/diag/rdbms/test3/TEST3/trace/alert_TEST4.log
>  { 
>  daily
>  rotate 15
>  compress
>  copytruncate
>  delaycompress
>  create 0640 oracle dba
>  notifempty
>  }
>  [oracle@testserver ~]$ cat oracle_asm_log
>  /u01/app/oracle/diag/asm/+asm/+ASM1/trace/alert_+ASM1.log 
>  { 
>  daily
>  rotate 15
>  compress
>  copytruncate
>  delaycompress
>  create 0640 oracle dba
>  notifempty
>  }
>  [oracle@testserver ~]$ cat oracle_listener_log
>  /u01/app/oracle/diag/tnslsnr/TESTSERVER/listener_scan2/trace/listener_scan2.log /u01/app/oracle/diag/tnslsnr/TESTSERVER/listener_scan1/trace/listener_scan1.log /u01/app/oracle/diag/tnslsnr/TESTSERVER/listener/trace/listener.log 
>  { 
>  daily
>  rotate 15
>  compress
>  copytruncate
>  delaycompress
>  create 0640 oracle dba
>  notifempty
>  }
>  
> ```

3. Put three configuration files to /etc/logrotate.d/ then you will see the log files will be rotated on next day. You can find the [code](https://blog.pythian.com/wp-content/uploads/gen_logrotate_config.zip) here and enjoy!

## Oracle Database Consulting Services

Ready to optimize your Oracle Database for the future?

 

[View full post](https://www.pythian.com/blog/log-rotation-oracle-database)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Howie Jiang"
  },
  "dateModified" : "2026-02-02T09:36:01.323Z",
  "datePublished" : "2018-01-11T05:00:00Z",
  "headline" : "Log rotation for Oracle database",
  "image" : {
    "@type" : "ImageObject",
    "height" : 60,
    "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
    "width" : 60
  },
  "mainEntityOfPage" : "https://www.pythian.com/blog/log-rotation-oracle-database",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Pythian Blog"
  }
}
```