Thursday, August 29, 2013

Rotating Oracle Listener.log file

Oracle database logs doesn’t rotate by it self.
As time goes by, the server may hold logs that are too big to read and takes too much storage space.
This can get your server to a maximum capacity or cause the listener can't start.

The best solution is to use logrotate:

There are 2 log files needs to be rotate:
Alert log and Listener log

Create new logrotate rules by edit a files under /etc/logrotate.d/

/etc/logrotate.d/oracle-alert

# Logrotate file for Oracle Alert

/home/oracle/admin/[SID]/bdump/alert_[SID].log {
missingok
weekly
rotate 4
compress
delaycompress
create 640 oracle oinstall
}


/etc/logrotate.d/oracle-listener

# Logrotate file for Oracle Listener

/home/oracle/product/10.2.0/network/log/listener.log {
missingok
daily
rotate 31
compress
delaycompress
create 644 oracle oinstall
prerotate
su - oracle -c "lsnrctl set Log_status off"
endscript
postrotate
su - oracle -c "lsnrctl set Log_status on"
endscript
}


Notice:delaycompress
This command can be useful if you want the archived logs to be compressed, but not right away.
With "delaycompress" active an archived log won't be compressed until the next time the log is rotated.
Note that "delaycompress" only works if you also have "compress" in your config.

To test it out:
/usr/sbin/logrotate -vdf /etc/logrotate.conf

To force run it:
/usr/sbin/logrotate -vf /etc/logrotate.conf

Reference:
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-centos-part-1
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-centos-part-2

8 comments:

  1. What i don't realize is actually how you are not really much more neatly-appreciated than you may be now. You are very intelligent. You recognize therefore significantly in terms of this subject, produced me in my opinion believe it from so many various angles. Its like women and men are not involved until it is one thing to do with Lady gaga! Your own stuffs great. All the time maintain it up!

    ReplyDelete
  2. Somebody essentially help to make seriously articles I might state. This is the first time I frequented your web page and to this point? I surprised with the analysis you made to make this actual post extraordinary. Great task!

    ReplyDelete
  3. I was actually excited enough to drop a commenta response ;-) I do have 2 questions for you if you do not mind. Could it be just me or do a few of these comments come across like they are coming from brain dead folks? And, if you are posting at additional sites, I

    ReplyDelete
  4. Want to make people visit a blog and don't know how. Also can you give me a good blogging site that people visit a lot. Do they visit your blog within the blog site or externally?? Thanks..

    ReplyDelete
  5. Hi,

    I didn't understand one thing:
    Why do you use the parameter "rotate 31" if you rotate only the listener.log?

    Regards.
    Anatoli

    ReplyDelete
  6. It is a business request, we need keep the past month network data.
    Thanks for checking.

    ReplyDelete
  7. The original post can be found here
    http://www.mylinuxplace.com/rotate-oracle-logs/

    ReplyDelete