docs/main/administration-guide/comply/data-retention-policy.mdx
Mattermost stores all message history providing an unlimited search history to system admins and end users.
Mattermost Enterprise customers can set a global retention policy as well as custom retention policies to manage how long messages and file uploads are kept in Mattermost channels and direct messages in order to meet data retention compliance requirements.
<Warning>To set a global data retention policy:
Select Save. Messages and files older than the duration you set will be deleted at the specified server time, as applicable.
To set a custom data retention policy:
Save the settings. Messages and files older than the duration you set will be deleted at the specified server time, as applicable.
You can also run the deletion job manually at any time by selecting Run Deletion Job Now in System Console > Compliance > Data Retention Policy.
<Note>If using data retention with ElasticSearch, ensure the ElasticSearch aggregate search indexes setting is set to a value that is greater than your data retention policy in days.
</Note>The message is removed from the Mattermost user interface and deleted from the Posts table. The message is no longer searchable and cannot be retrieved in saved posts lists.
Replies that did not exceed the message duration are still displayed in the user interface. However, further replies are no longer possible.
If there was a file attached to the message, it will be removed from the user interface only.
The web and desktop app cache posts. Posts deleted by a data retention job will be visible to end users until they clear their cache and refresh.
The file attachment is removed from the Mattermost user interface, deleted from the FileInfo table, and from your local disk or Amazon S3 service as specified in System Console > Environment > File Storage.
Pending in the deletion job table with no details?This usually means another data retention job is in progress. You can verify this in the deletion job table in System Console > Compliance > Data Retention Policy.
When messages or files are deleted, they are no longer searchable in the Mattermost mobile apps.
In v1.5 and later of the iOS and Android apps, messages and files are deleted from local storage in the following cases, if they exceed the retention policy duration:
In v1.4 and earlier of the mobile apps, messages and files are not cleared from local storage when the data retention policy is enabled.
Mattermost provides the status of each data retention job in System Console > Compliance > Data Retention Policy. Here, you can see if the job succeeded or failed, including the details of the error.
Additionally, any failures are returned in the server logs. The error log begins with the string Failed job and includes a job_id key/value pair. Data retention job failures are identified with worker name EnterpriseDataRetention. You can optionally create a script that programmatically queries for such failures and notifies the appropriate system.
Data retention runs once a day at the time specified in the config.json file. Changing the retention period does not automatically schedule any additional run of the data retention job - it only updates how long data is kept in Mattermost.
No, the new config is updated, but the system admin does not receive any feedback on what the effects will be (e.g. reporting of how many messages are to be deleted).
Prior to v5.20, data retention would delete all user activity corresponding to the data retention time configuration. From v5.20, the audit table will retain the user activity corresponding to the data retention time configuration.
Posts and attachments in archived channels are affected by the data retention job. If a post exceeds the age configured for the data retention job it will be deleted from the database.
Data retention runs the actual deletion query in batches, deleting data in blocks of 1000 records per query. This is so the database won’t be locked up for extended periods of time with long-running queries. Keeping to this limit keeps the query down to a few milliseconds' execution time on the database itself.
Each batch of data is deleted based on indexes - making the queries quick to execute on small batches. This helps the server remain fully responsive while the process is running.
The job scheduler runs the data retention job based on the time specified in the configuration settings. At this time a DEBUG-level log line is printed: Scheduling data retention job.
When a job server picks up that scheduled job for execution, a DEBUG-level log line is generated: Worker EnterpriseDataRetention: Received a new candidate job.
When the job is complete, an INFO-level log line is generated: Worker EnterpriseDataRetention: Job is complete.