Published : 2020-10-25

Mattermost - cleanup old posts

Mattermost community doesn’t include by default post retention on channels. It’s an enterprise only feature, which permits to have custom retention per channel.

If you are using Mattermost community for a long time you may need to cleanup very old posts globally to prevent your database size to increase infinitively.

To perform this cleanup you can play the following queries on your database (hot) to remove definitively posts older than a period (here 6 months):

delete from posts where createat < extract(epoch from (now() - interval '6 months'))::int8 * 1000;
delete from reactions where postid not in (select id from posts);
delete from fileinfo where postid not in (select id from posts);

We have to cleanup some referenced here on other tables because there is some missing constraints on mattermost database. I posted an issue on Github, i hope they will add this to make our life easier (and theirs :))

Note: this cleanup has been done on Mattermost 5.28.0