The discussion revolves around cleaning up the email_logs table in a Discourse installation to free up disk space. garthomite noticed the table was consuming 12GB, primarily due to spam-related email_reject_destination entries. zogstrip confirmed that logs with empty reply_key (like rejects and digests) can be safely deleted, while those with a reply_key should be retained to preserve reply functionality. A solution was implemented via a site setting, delete_email_logs_after_days, initially set to 1 year, but later reduced to 90 days to prevent excessive growth. The team also optimized the table structure by removing unnecessary columns, moving skipped emails to a separate skipped_email_logs table, and introducing a lightweight PostReplyKey table to allow safe deletion of old logs. tgxworld led the technical changes, including dropping old columns and refining the reply failure message, which was simplified after feedback from sam and zogstrip.
I was looking to free up some disk space on our discourse installation and I noticed that the email_logs table was using a substantial amount of space compared to everything else. For context all other tables amount to about 100mb but the e-mail logs are in the range of 12GB
I’m curious, is there a process to limit the amount in this table? Can older entries be removed on a regular basis?
You can safely trim all the email_logs which have an emptyreply_key (eg. “email_reject_*” and “digest”).
For the ones that have a reply_key, if you delete them, you’ll prevent users from replying to that email. So I guess you could be fine deleting some that are older than X months.
For busy sites that send out alot of emails, this table can bloat fairly quickly. There are some optimizations that we can do on the table to make it use less disk space but that’ll have to wait till Discourse Version 2.1.
PERF: Split skipped email logs into a seperate table. · discourse/discourse@ae8b0a5 · GitHub
Emails that have been skipped are logged into another table skipped_email_logs from now on so that we can avoid creating indexes like this. Also, we were previously storing the skipped reasons as strings in the database which was inefficient and the “locale” of the reason is decided when the record is created. Going forward, each skipped email log contains a reason_type which is stored as an integer in the database. The reason is then translated on demand based on the given reason_type.
Note that I’m playing it safe here and have yet to drop the old columns from the tables so you’ll actually see an increase in disk space used for a short period of time.