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 {
create 660 mysql mysql
size 5M
[ -f /var/run/mysqld/mysqld.pid ] && /bin/kill -HUP `cat /var/run/mysqld/mysqld.pid`

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?

  • 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 Apr 8 '15 at 12:44
  • 1
    You are right. I fixed it. – Thomas Kahle Apr 9 '15 at 7:21

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:


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.

  • OK, it does not clarify the issue, but it helps. Thanks. – Thomas Kahle Apr 9 '15 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) – Per Lundberg Sep 16 '19 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.