4

I'm using logrotate to rotate mysql output. When cron runs logrotate, I get frequently get an e-mail with the following content:

error: Compressing program wrote following message to stderr when compressing log /var/log/mysql/mysqld.err-20150408:
gzip: stdin: file size changed while zipping

indicating that after logrotate moved the file and called gzip on it, the file was still open and mysql was writing to it. Here's my logrotate config for mysql:

/var/log/mysql/mysql.err /var/log/mysql/mysql.log /var/log/mysql/mysqld.err {
monthly
create 660 mysql mysql
notifempty
size 5M
sharedscripts
missingok
postrotate
[ -f /var/run/mysqld/mysqld.pid ] && /bin/kill -HUP `cat /var/run/mysqld/mysqld.pid`
endscript
}

This is the unmodified file that is shipped with Gentoo's mysql package, so I doubt there are problems with it. I have no trouble with other logs being rotated.

Any ideas what may be going on?

2
  • 3
    The title of your question may indicate a misconception. It's not logrotate that has to stop writing to the file and close it, it's whatever application is writing it, in this case MySQL.
    – Celada
    Commented Apr 8, 2015 at 12:44
  • 1
    You are right. I fixed it. Commented Apr 9, 2015 at 7:21

1 Answer 1

5

The gzip error message states pretty much what is going on -- the file is being written to (by MySQL in this case) during compression. Try using delaycompress (with compress); from the man page:

delaycompress

Postpone compression of the previous log file to the next rotation cycle. This only has effect when used in combination with compress. It can be used when some program cannot be told to close its logfile and thus might continue writing to the previous log file for some time.

2
  • OK, it does not clarify the issue, but it helps. Thanks. Commented Apr 9, 2015 at 7:26
  • 1
    Thanks for this, very helpful for me right now when I ran into similar problems with a different program (logs were not being rotated correctly, was seeing occurrences of this error in the log files) Commented Sep 16, 2019 at 8:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .