Reclaiming Synapse disk space with purge history and VACUUM
Purge history removes old events from a Synapse room's timeline, but the disk space it frees usually stays inside PostgreSQL until a separate VACUUM step returns it to the operating system. Teams need this work when the synapse database keeps growing, cleanup jobs have run, and the volume still shows little free space. This section explains why that happens and what the rest of this page covers: the purge history admin API, retention jobs, why usage does not drop on its own, and how to plan a VACUUM FULL around downtime.
Before you purge anything, confirm which rooms drive growth and whether users expect their history to stay. Purging is destructive: once events are deleted from the timeline, they cannot be recovered from the homeserver, so take a verified PostgreSQL backup first. Check the Synapse configuration manual and the admin API documentation for your exact release, since the purge endpoint and its options are documented there, and confirm the retention settings your organization has agreed. Purges run as background work, so measure the database size before and after and expect the figures to move over a long period rather than at once.
Plan the VACUUM step separately. Ordinary autovacuum marks space as reusable inside the database files, which keeps the file size flat, while VACUUM FULL rewrites tables into new files and returns space to the disk. It takes an exclusive lock on each table it rewrites, so Synapse must be stopped or fully drained during the run, and the work needs free disk roughly equal to the size of the tables being rewritten (confirm this with your PostgreSQL version's documentation). Schedule a maintenance window, test the procedure on a restored copy, and keep the backup until the new size is verified.
Purge options and when each fits
This table compares the purge history API, scheduled retention jobs, plain VACUUM and VACUUM FULL on what each removes, whether it needs downtime, how it affects disk space and when a team should choose it. Read each row as a separate step: purging frees rows inside PostgreSQL, while only VACUUM FULL typically returns that space to the operating system, and the exact parameters must be confirmed against the Synapse admin API and configuration manual for your version.
| Option | What it removes or changes | Downtime and disk effect | When it suits a team |
|---|---|---|---|
| Purge history API, single room | Events and state before a chosen event in one room, through the admin API (confirm endpoint and parameters for your version) | No planned downtime. Rows are marked free inside PostgreSQL, so the data directory size usually stays the same until a VACUUM FULL runs. | A few large rooms have grown unusually large and the admin wants a controlled, room-by-room cleanup. |
| Purge history API, timestamp cutoff | Events older than a cutoff timestamp across rooms, through the admin API (confirm cutoff parameter names in the admin docs) | No planned downtime. Freed rows are reused by PostgreSQL but do not shrink files on disk by themselves. | A team wants one global cutoff for old history and can explain the deletion to users before running it. |
| Scheduled retention jobs | Events older than the configured retention period, applied by Synapse on a schedule once retention is enabled in the configuration (confirm the retention settings for your version) | No downtime. Work runs continuously in the background, so the disk footprint falls slowly and only inside PostgreSQL. | A policy requires automatic deletion after a fixed period and the team accepts that space recovery is gradual. |
| Plain VACUUM | Marks dead row space in tables as reusable for future writes. It does not remove data that the purge already deleted from view. | Usually no exclusive lock on tables, so the server stays online. Disk usage returned to the OS is typically minimal. | Routine maintenance after large purges, to let PostgreSQL reuse space and keep bloat in check. |
| VACUUM FULL | Rewrites each affected table into new files and drops the dead space, then returns the reclaimed space to the operating system | Takes an exclusive lock on each table being rewritten, so Synapse must be stopped or drained for the duration. Needs free disk space for the new copy of each table during the rewrite. | A large purge has finished, the team has a maintenance window and the database volume needs actual space back. |
| Retention policy versus manual purge | Retention is a standing rule and applies to new history over time. A manual purge is a one-off action on existing history. | Neither needs planned downtime, but both reduce data that users can scroll back to. | A team should agree the user-facing expectations before choosing either, because deleted history cannot be restored from the server. |
| Backup before any option | Creates a restorable copy of PostgreSQL and configuration before data is deleted | Backup time depends on database size and tooling. Confirm the procedure in the backup and restore guidance for your deployment. | Every option above deletes or rewrites data, so a verified backup is a precondition, not an optional step. |
How to plan a purge and VACUUM FULL window
This sequence takes a Synapse homeserver from an agreed retention decision to a tested purge and a planned reclaim of database space, with a check at each stage so that production changes only happen after staging has shown the expected result.
Confirm Synapse and PostgreSQL versions
The platform engineer records the running Synapse release and the PostgreSQL major version on the production host, then compares both with the upgrade notes for that release. Synapse 1.143.0 and later require PostgreSQL 14 or newer, so an older database must be upgraded before anything else. The step is done when the versions are written into the change ticket and confirmed as supported. Check the current release on the Synapse releases page and read every upgrade note between the installed version and the target.
Take and verify a full backup
The database owner takes a full PostgreSQL dump or base backup and copies the homeserver configuration and signing key to separate storage. Media is backed up or its retention is confirmed separately, because purging history does not restore deleted events. The check is a test restore of the dump into a scratch database, followed by a row count comparison against production. Rollback after a Synapse schema change can be difficult, so this backup is also the recovery point for the whole window.
Measure database and volume size
The operator records the size of the Synapse database, its largest tables such as events and state groups, and the free and used space on the volume holding the PostgreSQL data directory. These numbers are the baseline against which the purge result will be judged. Use queries against the database size functions and the filesystem report on the host. The step is done when the baseline is saved with a timestamp, so that later measurements compare like with like and do not rely on memory.
Agree retention scope with business owners
The homeserver owner and the business and compliance owners agree which rooms, time window and event types may be purged, and which rooms are excluded, such as legal hold or regulated records. They also agree how users will be told about history loss in affected rooms. The output is a written scope naming the cut-off, the room list or rule, and the approver. Confirm the retention requirements with your legal and compliance teams before any delete is run, since a purge cannot be reversed from the database.
Run the purge on a staging copy
The operator restores the production backup into a staging environment running the same Synapse and PostgreSQL versions, then runs the purge history API or the configured retention job against the agreed scope. Purge runs in the background, so the operator waits for the job to report completion and records the purge identifier and any errors. The check is that the purge finishes without errors and that the scoped rooms show the expected missing history while excluded rooms are unchanged.
Measure the staging result and plan VACUUM FULL
The operator repeats the size measurements on staging to see how much space is now reusable inside PostgreSQL and how much the volume actually freed. Ordinary cleanup marks space for reuse but usually does not return it to the operating system, which is why disk usage often stays high after a purge. VACUUM FULL rewrites tables and needs free space on disk for the new copies, so the team confirms that headroom on staging. Schedule the window with downtime for Synapse and the database, and confirm the expected rebuild time by timing it on staging.
Purge production and verify sync, federation and size
During the approved window the operator stops Synapse, runs VACUUM FULL on the affected tables, starts Synapse again, and then repeats the purge against production using the scope from staging. Afterward the operator checks that clients can sync, that a test message reaches a remote server, that federation sends succeed, and that the database and volume sizes match the staging projection. The step is complete when these checks pass and the results, including the new baseline, are recorded in the change ticket.
How purge and VACUUM fit together
The path starts with a purge request that deletes events from the Synapse database rows in PostgreSQL. Those deleted rows leave dead space inside the table files, so the database size does not fall right away. Plain VACUUM marks that space as reusable inside the database, while VACUUM FULL rewrites the tables so the space returns to the volume, at the cost of downtime and temporary extra disk use. Check the disk usage before and after each step.
Purge removes rows, and only VACUUM decides whether the disk space comes back.
Risks to manage before deleting room history
Purging room history removes events that users, other servers and your own restore plan may still depend on. The cards below cover the risks that matter most on a Synapse homeserver, and each one names the check to run before anything is deleted.
Loss of expected history
Members scroll back through a room and find gaps once old events are gone. Purging is not reversible for those events, so the first question is which rooms and which dates the organization has agreed to clear. Ask the business owners of key rooms to confirm the retention window in writing, and list rooms that need a longer window before running any purge.
Irreversible deletion without a tested backup
A purge cannot be undone from the homeserver itself. Take a PostgreSQL dump and copy the configuration and signing key, then restore that backup to a separate host and confirm that the server starts and the affected rooms load. Only then should the purge run against production data.
Rooms still in active use
Purging history in a room where people are still talking can remove context that new members and sync clients expect. Choose a purge point well behind the current forward extremities, and confirm with the room's admins that the period is closed before the purge starts.
Federation effects on other servers
Other homeservers keep their own copies of shared rooms, so a local purge does not remove history from them. Users on remote servers may still see events you deleted, and backfill requests can behave differently afterward. Ask your federation partners what they retain and document this limit for your users.
Insufficient free disk space for VACUUM FULL
VACUUM FULL rewrites each table it processes, so PostgreSQL needs free space for the new copy while the old one still exists. Measure the size of the largest tables and the free space on the volume before scheduling the rebuild. If the headroom is short, free space elsewhere first or plan a larger volume rather than starting a rebuild that fills the disk.
Long locks during the rebuild
VACUUM FULL takes an exclusive lock on each table it rewrites, and Synapse cannot serve those queries until the lock is released. Stop Synapse or its workers during the window, announce the downtime to users, and time the rebuild outside peak hours. Confirm the expected duration on a restored copy of your database before scheduling it on production.
How the approach changes by deployment type
On a single host installed from operating system packages, Synapse and PostgreSQL usually share one machine, and the database sits on a local or attached volume managed by your team. Downtime is entirely under your control: you stop the Synapse service, run the database maintenance, and start it again, so the window is set by your own change process. Growing the disk is a host-level task, often a logical volume extension or a new attached volume followed by a filesystem resize.
- Database location: PostgreSQL runs as a system service on the same host, so the purge and VACUUM commands run directly on that machine.
- Downtime scheduling: You decide when to stop
matrix-synapseand when to restart it, and you can agree the window with users in advance. - Volume work: Check free space on the filesystem holding the PostgreSQL data directory and the media store separately, since they may be on different mounts.
- Verification: Compare filesystem usage before and after, and confirm the database has been reclaimed rather than only the tables being dropped.
- Rollback: Take a backup of the database before any destructive purge, because a single host gives you no second node to fail over to.
Before scheduling any window, confirm the PostgreSQL major version and the storage layout on the host with your own administrators.
In a container deployment, Synapse runs in its own container while PostgreSQL may run in a separate container, on a managed database service, or on a host you already operate. Where the database lives changes who controls its storage and maintenance. Downtime is still your decision, but stopping the Synapse container does not automatically stop the database, and the volume behind the database is usually a named or bind-mounted volume that needs its own capacity check.
- Database location: Confirm whether PostgreSQL is a sibling container, an external service or a managed instance, because each one has a different maintenance path.
- Downtime scheduling: Stop or scale the Synapse container first so no writes compete with the purge, then run the database work.
- Volume work: Identify the volume backing the database data directory and check its capacity on the container host, since expanding a container volume depends on the storage driver or platform.
- Verification: Check the volume usage on the host, not only inside the container, because the container view can hide the real filesystem.
- Image versions: Pin the Synapse image tag you tested, so a restart after maintenance does not pull a newer release unexpectedly.
Confirm your storage driver's resize behavior and the exact PostgreSQL image tag with your platform team before the change.
On Kubernetes, such as an ESS Community deployment on a cluster, PostgreSQL may run as a managed operator-based instance, an external service, or a chart-provided database. Downtime is coordinated through the workload controllers, so you scale the Synapse components down before database work and scale them back up afterward. Volume resizing depends on the storage class and whether the persistent volume claim supports expansion, which varies by platform.
- Database location: Identify whether the database is inside the cluster or external, since an external database needs its own maintenance window and access path.
- Downtime scheduling: Scale the relevant Synapse deployments down to zero replicas before the purge and VACUUM, and record the replica counts so the restore order is clear.
- Volume work: Check whether the storage class allows volume expansion and whether the claim can be resized online or needs a pod restart.
- Verification: Read the persistent volume claim capacity and the database size from inside the cluster, and confirm the workloads are healthy before users return.
- Configuration state: Save the values, secrets and the Helm release state before changing replica counts, so the rollout does not drift from the configuration you intend to run.
Ask your cluster administrators whether the storage class supports expansion and who owns the database operator.
Operational controls around purging
Purging history is destructive and cannot be undone from the homeserver itself, so the operational control that matters most is who is allowed to run it. Limit the purge API to a small named group of Synapse server administrators, keep the admin token out of shared scripts and automation, and require that the person running a purge is not the only person who knows the target room and cutoff. Before any run, write down the room ID, the chosen cutoff, the expected effect on users who will lose scrollback, and the approver's name. Treat the retention jobs the same way: changing a retention policy changes what gets deleted later, so it needs the same sign-off as a one-off purge.
Record every admin action in a place the platform team does not control alone. Synapse's HTTP access logs show which admin endpoint was called and from where, but they do not hold the approval record, so store the ticket, the approver and the timestamp alongside the command output in your change system. Confirm with your own log pipeline that purge requests reach a retained, tamper-resistant store, and check how long your organization keeps those records. Decide before the first purge how long you will keep the approval record and the purge output, since those records are often needed longer than the chat history they describe.
Set a backup retention policy before purging, not after. Backups taken before a purge still contain the deleted history, so the policy must say how long pre-purge backups live and who can restore them. Confirm with your legal and compliance owners whether that retention is acceptable for the data involved; this page does not make that determination. After the change, monitor PostgreSQL database size and the volume holding media and logs over several days, because the freed space may not be returned to the operating system until a planned VACUUM FULL. Alert on growth trends rather than only on absolute size, so the next purge decision is based on measured data.
Questions teams ask before purging Synapse history
What drives the cost and effort of a purge and VACUUM FULL?
The effort depends on how much history you remove, how large the affected rooms are, and how much downtime your users and operators can accept. A purge deletes events and state that fall outside the chosen point, so the work scales with the volume of history and the number of rooms involved. VACUUM FULL rewrites tables to return space to the operating system, so its effort grows with the size of the tables it touches and the free disk needed during the rewrite. Cost components are mostly internal staff time for planning, a tested backup, the maintenance window, and any specialist time if you buy help. Ask any provider to break the quote into planning, execution, verification and rollback, and to state which items are one-time and which recur if you purge on a schedule.
How long does a purge take, and what sets that time?
Duration depends on the size of your PostgreSQL database, the number of rooms and events in scope, the database server's disk speed, and whether Synapse keeps serving traffic during the run. Purge jobs are usually run in batches, and VACUUM FULL takes an exclusive lock on each table it rewrites, so the table-level blocking can last as long as the rewrite itself. Measure before you commit: check the size of the tables reported by your database, run the purge against a restored copy of production, and time both steps. Confirm the expected duration with your Synapse version's documentation and with the vendor support channel before you schedule downtime, since the figures depend on your own data.
What does the work need from our internal team?
The internal team needs database administration skills, Synapse operations knowledge, and authority to approve a maintenance window. Typical roles include a PostgreSQL administrator who can check table sizes, run backups and verify restores, a Synapse operator who knows the admin API and the retention settings, and a product or compliance owner who agrees which history can be deleted. Someone must also own the communication plan for users in affected rooms, because purged history cannot be recovered from the server. Plan for staff time before, during and after the work, including a rehearsal on a copy of the database.
Can our team run a purge and VACUUM FULL without outside help?
Yes, if your team already runs PostgreSQL backups, has a tested restore path and can operate Synapse safely. The steps are documented in the Synapse admin API and the PostgreSQL manual, and many teams handle them internally. Outside help is most useful when the database is large, when you cannot take a long outage, when compliance requires documented evidence of the change, or when no one on staff has done a restore recently. DeployOpen can plan, implement and document this kind of change in infrastructure you control, with the scope and deliverables agreed in writing before work starts. Whichever route you take, make the backup and restore check a precondition, not an afterthought.
Does purging history remove data held by other servers?
No. A purge only changes the data stored on your homeserver, so events that other homeservers already hold stay on those servers. Federated rooms are replicated, which means a local purge cannot reach copies that remote servers have stored. If a user on another server sends or receives messages in a shared room, those events remain available there. Plan your data-protection position around this fact, and ask your legal or compliance owner to confirm whether a local purge meets your obligations for rooms that span organizations. Check the Synapse federation documentation for how remote events are stored before you promise deletion to users.
How do we tell whether the database or the volume is the real problem?
Start by comparing the space used by the PostgreSQL data directory with the free space reported by the operating system on the volume that holds it. If the database files are large, check which tables and indexes take the most space, then whether the growth is in events, state groups or media metadata. If the database is small but the volume is full, look at logs, WAL files, backups, media directories and other applications on the same disk. Free space inside PostgreSQL does not return to the operating system without VACUUM FULL, so a full volume with a database that has reclaimable free space points to a table rewrite, while a full volume caused by media or logs points to a different cleanup. Confirm the findings with your database and Synapse monitoring before you act.
What risks should we plan for before the work starts?
The main risks are losing history that users still need, running out of disk during the table rewrite, locking tables for longer than the window allows, and leaving the server in a state that is hard to roll back. Take a verified backup of PostgreSQL and the Synapse configuration before any step, and confirm there is enough free disk for the rewritten tables. Rehearse the change on a restored copy, record the timings, and agree a rollback plan that includes restoring from backup. Keep a written record of which rooms and time ranges were purged so the change can be explained to users and auditors.
What a DeployOpen engagement on purge and VACUUM covers
A DeployOpen engagement on this work starts with an assessment of where the space goes. We review the size of the PostgreSQL database and the media store on the volume, check which tables and rooms account for most of the growth, and confirm the Synapse version and database engine in use, since the purge options and the upgrade notes that apply depend on them. The output is a written picture of the growth drivers, so the retention decision rests on evidence rather than on a disk alarm. We also confirm whether the server runs on a single host or as workers, because that affects how much downtime the VACUUM step needs and who must be told.
The core decision is the purge scope, and it belongs to the client. We work with your administrators, data protection lead and legal contact to agree which rooms, time ranges and event types may be removed through the purge history API or a retention job, and what users will and will not be able to see afterward. Before anything touches production, we rehearse the purge and the VACUUM on a restored copy of the database, record the duration and disk change, and confirm that the homeserver starts and serves rooms cleanly. The rehearsal is what turns a planned window into one the client can trust. The restore path for the same copy should be confirmed against your backup procedure first.
Production work follows a written runbook: the purge run, the agreed maintenance window, the VACUUM FULL execution with disk space checked beforehand, and post-run checks on logins, sync and federation. Deliverables include the assessment, the agreed purge policy, the runbook, the rehearsal record and a closing document describing what was removed, what was reclaimed and what recurs. Engagements are fixed-scope, so the scope, deliverables and timeline are agreed in writing before work starts, and DeployOpen does not publish a price list. Ask for a quote that itemizes assessment, rehearsal, the production window and documentation, and confirm with the vendor which Synapse release your team plans to run.
How DeployOpen scopes and delivers Synapse disk recovery
DeployOpen plans Synapse disk recovery as a written, fixed-scope piece of work: which rooms and retention windows are in scope, what is backed up first, and when downtime for VACUUM FULL is acceptable. The work is carried out inside your own infrastructure, with the purge, the database maintenance and the evidence of results documented so your team can repeat it.
How we scope
- Inventory database size, table growth and free space before any purge is proposed.
- Agree which rooms, retention windows and history ranges the purge will cover.
- Confirm the Synapse version, PostgreSQL version and maintenance window in writing.
How we build
- Take and verify a PostgreSQL backup and config copy before the first purge runs.
- Run purge history steps on a non-production copy first, then record the measured effect.
- Plan VACUUM FULL timing, disk headroom and rollback steps with your operations team.
How we hand over
- Deliver a runbook with exact purge commands, parameters, checks and expected output.
- Document the downtime window, the restore path and who approves each destructive step.
- Walk your administrators through a repeat run so the procedure belongs to your team.
How we support
- Offer retainers for scheduled purges, database maintenance and upgrade-related checks.
- Retest disk usage and database health after each agreed maintenance cycle.
- Revisit retention policy when user expectations, legal requirements or room volume change.

