How to get logrotate work for MariaDB?

I deployed MariaDB with Docker in Unraid, I know that the best choice is solving errors in the log. But I still want to rotate the error log.

I created the following configuration file native to Unraid(/etc/logrotate.d/mariadb):

/mnt/user/appdata/mariadb/databases/mariadb.err {
        su nobody users
        missingok
        create 660 nobody users
        notifempty
        daily
        minsize 1M
        maxsize 100M
        rotate 30
        dateext
        dateformat .%Y-%m-%d-%H-%M-%S
        compress
        delaycompress
        sharedscripts 
        olddir ../archive/
        createolddir 770 nobody users
    postrotate
        # just if mysqld is really running
        if docker exec mariadb test -x /usr/bin/mysqladmin && \
           /docker exec mariadb usr/bin/mysqladmin ping &>/dev/null
        then
           /docker exec mariadb usr/bin/mysqladmin --local flush-error-log \
              flush-engine-log flush-general-log flush-slow-log
        fi
    endscript
}

After executing logrotate --force /etc/logrotate.d/mariadb, everything seemed OK only that the new logs were still appended to the archived file, the mariadb.err file was empty.

Rotating Logs on Unix and Linux - MariaDB Knowledge Base

Not helpful. I’ve seen this documentation.

I finally figured it out. Just tell MariaDB to reopen the log file, put the following line in the postrotate block:

docker exec mariadb sh -c '/bin/kill -HUP $(cat /var/run/mysqld/mysqld.pid)'

well, the documentation that you’ve seen literally covers what you need to do. Your “solution” is close enough (but risky) to what is literally in the documentation that you have “seen” that it will likely work. Remember, seeing the documentation is not nearly as useful as reading it

That said, killing the process sounds like a great way to corrupt your data.