Regular maintenance

As emails are added and deleted it's good practice to check the database is in good order and remove emails that have been deleted.

dbmail-util is your friend.

DBMail is designed to be highly optimised so it's fast and reliable. To achieve this there are no long running transactions that might cause a database lock so there are checks to ensure the database is in good order.

Unless you are running a very large system, the following is a good monthly task:

dbmail-util --all-checks

Deleting emails is a two step process, first user deleted emails are marked for deletion, second they are purged from the database. If you run dbmail-util monthly then you leave a window of a month when emails deleted in error can be recovered.

--all-checks should be run once per maintenance period, it first purges messages with a status of deleted, then sets the deleted status for messages flagged for deletion. If you run dbmail-util --all-checks twice it marks deleted emails for deletion then purges them so they are gone completely. They may recoverable from normal database logs and backups but that is a non trivial task.

As emails are checked as they enter DBMail it's unusual for an invalid email to be found in the database, but for historic reasons there are checks for message integrity, checks for caching body/header/envelope and empty caches, dangling/invalid aliases and forwards.

Database maintenance

All databases need regular maintenance, see your database documentation for further guidance.