Purging old media with Synapse media retention: when teams need it
Self-hosted Matrix operators turn on Synapse media retention when the media store keeps growing with files nobody needs anymore. The feature purges cached remote media, which is copies of files that other homeservers sent into rooms your users joined, after a set period. It can also purge local uploads that have not been accessed for that period. The retention rules are configured in the media_retention block of homeserver.yaml, where you set separate periods for remote media and local media. Confirm the exact keys and their behavior against the Synapse configuration manual for your release before you copy any example into production.
Turning on the remote media purge is usually the low-risk first step. Remote media is a local cache, so users can still see the file if another server still hosts it, and the purge does not remove anything a user uploaded. Local media is different. Once a user's upload is deleted, the file is gone from your server and from every room that linked to it, and no storage setting can bring it back unless you kept a backup. Plan to run retention jobs on a schedule that suits your team and confirm the job's effect in a test environment with a copy of your media directory.
Deleting uploads is a policy decision, not only a storage setting. Before you enable a local media period, agree with legal, compliance and room owners how long users can expect their files to remain available, what happens to files in rooms where people still need them, and whether any legal hold or records obligation overrides the purge. Write that agreement into your acceptable use or data retention policy and tell users about it. Your compliance team should also decide how the purge interacts with your backup retention, since a restored backup can bring deleted media back.
Media retention options and when each fits
This table compares the Synapse media retention settings by what each one deletes and when it fits. Read each row as a separate decision: remote cache expiry is low risk, while local media expiry removes user uploads and needs an agreed policy first. Verify exact key names and defaults in the configuration manual for your Synapse version before you change anything.
| Setting | What it deletes | When it fits | What to confirm first |
|---|---|---|---|
| Remote media lifetime (media_retention, remote_media_lifetime) | Cached copies of media fetched from other homeservers, which Synapse can download again when a user requests them | Your store grows mainly from federated rooms and you accept re-downloads for old remote files | Exact key name and default in the configuration manual for your version, and whether re-fetching is slow for your users |
| Local media lifetime (media_retention, local_media_lifetime) | Uploads made by your own users, which cannot be recovered from another server if removed | Only after your users and legal or records owners have agreed that uploads expire on a stated schedule | Written user notice, retention rules for business records, and whether any room depends on those files |
| Per-room or per-user exceptions, if documented for your version | Nothing is deleted for the excepted rooms or users, while the general lifetime still applies to everyone else | A few rooms hold files that must stay longer, such as policy or incident channels | Whether your version supports these exceptions, and how the exception list is maintained |
| Media admin API purges (manual deletion by age or media ID) | Selected media files chosen by an administrator, on demand | One-off cleanup of a known set of files or a specific user's uploads after a documented request | Who approves deletion, and whether a backup of the media store exists before the purge |
| No retention setting (keep everything) | Nothing is removed automatically | Compliance or legal hold requires all media to stay, or the store is still small | Monitoring of media store size so growth is caught before disks fill |
| Retention job run schedule | Controls when expired media is deleted, not what is deleted | You want deletion in quiet hours and a predictable effect on I/O | How long a run takes on your store, and whether it needs a maintenance window |
Setting up media retention without losing uploads
This sequence sets a media retention policy on a Synapse homeserver in a controlled order. It starts with measuring the media store and agreeing the rules with users, then backs up, configures, tests, schedules and verifies the purge before it runs on production.
Inventory the media store and growth
The server administrator records the current size of the media directory on disk and the number of local and remote media items, using the media admin tooling for Synapse where it exposes that information. Record which users and remote servers account for most of the storage, and how fast the store has grown over recent weeks. Done when the team has a dated baseline that it can compare against after the first purge, and it knows which uploads are local and which are cached copies from other servers.
Agree the user policy in writing
Before any deletion, the service owner, privacy lead and the administrators agree in writing which content may expire, how long remote cached media is kept, and whether local uploads ever expire at all. The policy should state what users are told, which rooms or accounts are exempt, and who approves an exception. Confirm with your legal and compliance team how retention interacts with any records obligations. Done when a signed policy exists and users have been notified of the change.
Back up the media directory
Before changing any setting, the administrator copies the media store to separate storage and also saves the homeserver configuration and a database backup, so the two stay consistent. Confirm the copy is complete by comparing file counts and total size with the source, then restore a few sample files from the backup to a scratch location and open them. Done when a restore of sample media has been proven, not only assumed, and the backup location is recorded in the change ticket.
Set the retention keys in homeserver.yaml
The administrator adds the media retention settings to
homeserver.yamlusing the key names in the Synapse configuration manual for the release in use, and confirms those names against that version's documentation before editing. Start with the lifetime for cached remote media and leave local upload expiry unset until the policy from the earlier step is confirmed. Restart Synapse in a maintenance window and check the logs for configuration errors. Done when the server starts cleanly and the settings match the signed policy. See the Synapse configuration manual for the exact keys.Test the purge in a non-production copy
The team restores the backup into a test environment with the same configuration and runs the first purge there. Compare the file counts and disk usage before and after, and check whether any media from the exempt accounts or rooms was removed. Confirm whether your Synapse version offers a dry run or review output for this job, and use it if it does. Done when the purge result matches the expected change in the test copy and the team has signed off the numbers in writing.
Schedule the purge job
The administrator schedules the retention purge with the platform's job scheduler, such as a systemd timer or cron, and runs it at a time with low traffic. The job should write its output to a log that someone reviews. Keep the schedule and the command in version control with the rest of the configuration. Done when the first scheduled run completes and its log shows the expected results, and the owner knows where to find future logs.
Verify users can still see expected media
Using test accounts, the team checks that recent uploads in active rooms still load, that remote media fetched again after a purge displays correctly, and that media in exempt rooms is intact. It also checks that encrypted attachments open on the clients your users run. Record each check and its result, then share the report with the policy owner. Done when every check on the list passes or has an agreed follow-up, and the report is filed with the change record.
Agreeing user expectations before deleting uploads
A media purge deletes files that old messages still point to. In Matrix, a message stores a reference to an upload rather than the file itself, so once a local upload is removed from the media store, the message remains in the room but its image, document or attachment shows as unavailable. Users often assume a file stays available for as long as the message that shares it exists, and a retention job that runs on a timer will break that assumption without any warning in the chat itself. Before enabling any purge, decide whether your organization accepts that trade-off and tell people what it means in practice.
Write the rules into an acceptable use or retention policy before the first purge runs, and publish them where users sign up and where they upload. The policy should state how long uploads are kept, whether that period differs for cached remote media (which users did not upload and can usually fetch again from the origin server) and for local uploads, and who can ask for an exception. Settings such as the media retention options in the Synapse configuration manual control what gets removed, so the policy and the configuration must say the same thing. Confirm the wording of the notice with your own legal or privacy counsel, and tell staff which team answers questions about missing files.
Legal holds and compliance duties come before any scheduled deletion. If a matter, investigation or regulatory request requires preserving chat content, a retention purge can destroy evidence that someone must keep, so the platform owner needs a documented way to exclude affected rooms or accounts and a named person who confirms holds with counsel. Ask your compliance and legal teams which record-keeping and data protection obligations apply to chat attachments in your sector and jurisdiction, and whether they require a longer period than the one you plan to set. This page does not give legal advice; the answers to those questions define the retention periods you are permitted to configure.
Security and operational risks of purging media
A media purge deletes files that users may still expect to open, and the effects reach backups, encryption, file permissions and monitoring. Each risk below is a decision to make or a check to run before the first purge runs on a live server.
Deleting uploads users still need
A purge removes local media files that users uploaded, and the server cannot bring those files back afterward. Users may still expect to open an old image, PDF or voice note in a room, even though the event remains. Agree the lifetime with users and administrators before you enable the job, and tell users which uploads expire. Check whether your policy treats avatars and room attachments the same way before you set the value.
Synapse configuration manualRestores that miss purged media
A database backup and a media backup must describe the same point in time. If the database is captured after a purge, restored events point to files that no longer exist. If the media is captured from an older snapshot, the database can reference files purged after that snapshot. Record when each backup ran, and test a restore that opens an old attachment before you rely on the schedule.
Encrypted attachments and key backup
Attachments in encrypted rooms are stored as encrypted files, and the key needed to decrypt them travels inside the message event. Key backup can restore message keys, but it cannot restore a file that a purge already deleted. Ask your compliance team whether they expect to read old encrypted attachments, and confirm with the Synapse documentation how purged encrypted media behaves before you set a lifetime.
Media directory permissions
Synapse writes uploads and cached remote media to a media store on disk, and the purge needs write access to delete files there. Limit read and write access on that directory to the Synapse service account and to the operators who run backups. Keep the directory off shared volumes that other workloads can mount, and check ownership again after any container or volume change.
Monitoring purge job failures
A retention job that fails quietly lets the media store grow again, and users see no error. Review Synapse logs after each scheduled run to confirm that the job completed, and graph media directory size and free disk space so a stalled purge appears as a trend. Alert on disk thresholds as well as job errors, so a purge that stops running is caught even when nothing logs a failure.
Testing retention changes first
The Synapse upgrade notes warn that rolling back can be difficult because of database schema changes between releases, so treat a retention change as a change you may need to reverse. Run the first purge on a staging copy, and record file counts and disk use before and after. Keep a dated backup from before the first live run so a mistaken lifetime can be traced and corrected.
Synapse upgrade notesQuestions teams ask before purging Synapse media
What does a Synapse media purge cost in staff time, and what drives it?
Most of the cost is staff time: a policy owner who agrees the retention periods, an admin who runs and checks the purge, and someone who handles the user questions that follow. No supplied figure sets the hours, so the effort depends on how many people must agree the policy, how much storage access your team already has, and whether the purge is a one-off cleanup or a recurring job. Ask any partner for a written scope that lists who does each task, which parts are one-time (policy, first purge, verification) and which recur (scheduled retention, monitoring, periodic review). Recurring cost is usually the lower one once the job is set up.
How long does a first media retention rollout take?
The duration depends on the policy decisions, not on the Synapse configuration itself. Agreeing what counts as cached remote media and what counts as an upload worth keeping can take longer than setting the options. Other drivers include the size of the media store, the number of users who must be told, whether a backup exists before the first run, and the change window your organization requires. No supplied timeline applies to your environment, so ask for a plan with explicit checkpoints: policy sign-off, a test on a copy, a first purge on a small window, and a review of results.
What does the team need to provide before a purge starts?
Three things must be in place before anyone runs a purge. First, a named policy owner who can decide retention periods and answer for them to users and auditors. Second, storage access that lets your admin see the media store, measure it, and restore from backup if needed. Third, a change window that covers the purge and a short verification period afterward. Your team should also confirm that backups of the media store and the database are current, because a media purge removes files that the database still references in some cases.
Can an in-house Synapse admin run media retention alone?
Often yes, for a simple policy on a single homeserver with the media store on local or known storage. The admin needs to be comfortable reading the Synapse configuration manual, testing on a copy, and checking results. Teams usually bring in outside help when the policy involves legal or HR sign-off, when the media store sits on shared or object storage with its own lifecycle rules, or when a purge has to run inside a tight change window. Confirm with your admin which storage backend holds media and whether anyone else already runs backups against it.
What happens when a user opens an old room after their upload was deleted?
The room history stays, but the file behind an old upload may no longer be available. Users typically see a broken or missing attachment, and the event that referenced it remains in the room. This is why the user expectations must be agreed before deleting uploads, and why the notice to users should say what happens to attachments in older conversations. Ask your engineers to test a deleted attachment in a sample room so you know exactly what users will see before the first purge.
How do we recover if a media purge removed the wrong files?
Recovery depends on backups taken before the purge. If the media store was backed up with a known restore procedure, the affected files can be restored to a test location first, checked, and then copied back. Without a backup, deleted files cannot be recovered from Synapse itself. Before any purge, confirm that the media directory or bucket is covered by backups, that a restore has been tested, and that someone knows which retention settings were in force when the purge ran. Record the purge scope so you can explain the impact to users.
Does media retention satisfy our data protection obligations on its own?
No. Media retention limits how long cached remote media and unused uploads are kept, which supports a retention policy, but it is one control among several. Your compliance team still needs to decide what data must be kept, for how long, and how erasure requests are handled. Ask your privacy or legal owner to review the policy against your obligations, and confirm with your admin which parts of Synapse the retention settings cover before you describe them in a policy document.
How the retention job decides what to delete
The flow starts with media entering the media store, either as a local upload from a user or as a remote fetch cached from another server. The retention job checks each file's age against the configured lifetime for its type. Files within the lifetime are kept. Older files pass to the policy exception check, where anything covered by an exception is kept. Only older, unexcepted files reach the purge step. Confirm that a backup of the media store exists before the first purge, because deleted uploads usually cannot be recovered from Synapse itself.
Media arrives from users or remote servers and is kept or purged based on age and exceptions.
How DeployOpen scopes and runs media retention
DeployOpen plans media retention as part of the Synapse deployment it runs in your infrastructure. We agree what gets purged, what users are told and how deletions are verified before any retention job runs against production media.
How we scope
- Written scope names the media types, local and remote, that retention will cover and those it will leave alone.
- Scope records the retention periods agreed with your compliance and legal owners before configuration begins.
- Scope states the user communication, notice wording and acceptable-use changes that must be approved first.
How we build
- We configure media retention settings in the Synapse configuration on a non-production copy before production.
- We test purge behavior against a restored media store to confirm which files are removed and which remain.
- We check that the media store, database and backup jobs stay consistent after purge runs are scheduled.
How we hand over
- You receive documentation of the retention settings, approved periods, owners and the exact purge procedure used.
- Runbooks explain how to pause retention, confirm what a run will remove and recover from an accidental purge.
- Handover includes a short walkthrough so your platform team can run and review retention jobs without us.
How we support
- Retainer support covers Synapse upgrades that change media handling, with retention settings rechecked after each upgrade.
- Ongoing reviews track media store growth against the agreed periods and flag when a policy change is needed.
- Support is available as a retainer after handover, and the scope of any retainer is agreed in writing.

