Migrate Synapse from SQLite to PostgreSQL

A practical plan for moving a Synapse homeserver off SQLite with synapse_port_db, including downtime limits, the VACUUM trap and extra disk space. Scope, sequence and effort drivers for your own team or a partner.

On this page

Migrate Synapse from SQLite to PostgreSQL: what the move involves

If your Synapse homeserver runs on SQLite and you need PostgreSQL for production, the move is a documented, script-driven port. Following the two-phase method keeps the final cutover short. The Synapse project provides the synapse_port_db script for this job, and the work is planned around it rather than improvised. The main decisions are when to take the downtime window, who runs the steps, and whether the new database server is ready to be trusted with the homeserver's data.

The effort is driven by four things. The first is database size, since the initial port of an offline SQLite copy and the later catch-up run both scale with the data. The second is disk headroom: the Synapse docs note the database may take 25% to 100% more disk space after porting to PostgreSQL, so confirm free space on the PostgreSQL host before starting. The third is PostgreSQL readiness, meaning a supported major version, a tested backup and restore path, and a configured Synapse database user with the correct locale and encoding. The fourth is the downtime window you can accept for the final snapshot-and-restart step. Ask any partner for a quote that states each of these assumptions, and confirm the current version floors in the Synapse upgrade notes against your planned release.

Costs split between one-time work and recurring work. The one-time items are the port itself, the rehearsal against a copy of production, the cutover, and verification of rooms, users and media after restart. The recurring items are PostgreSQL maintenance, backups, and keeping Synapse and PostgreSQL on supported versions. Your own team pays for staff time and infrastructure, while a partner bills for the agreed scope. Before you commit, decide whether you will rehearse the cutover on a staging copy, since skipping that rehearsal is the most common source of an unplanned outage.

What maps cleanly from SQLite and what does not

This table compares each part of a SQLite-backed Synapse homeserver with where it lives after the move to PostgreSQL, and separates what the port script carries across from what you must move, rewrite or confirm yourself. Read the rows marked as manual work before scheduling the cutover, because they are the ones that cause failed or partial migrations.

ElementAfter porting to PostgreSQLWhat you must do
Rooms and eventsMoved into PostgreSQL tables by synapse_port_dbConfirm row counts and room access after cutover; no separate export is needed
Users, devices and access tokensMoved into PostgreSQL tables by synapse_port_dbTest logins and device sessions on the new database before reopening to users
Media metadataDatabase records move to PostgreSQLMedia files stay on disk and are not moved by the script; copy the media store separately
Media files on diskNot moved by the scriptCopy the media directory to the new host and confirm the media paths in configuration still resolve
homeserver.yaml database sectionNot rewritten by the scriptReplace the sqlite3 database block with a postgresql block that points at the new server and credentials
Signing keys and server_nameKeys are read from the signing key file; server_name is a configuration valueKeep the same signing key file and server_name, since changing either breaks federation identity
Custom SQL, reports and external toolsNot migrated; any tooling written against SQLite files is left behindRewrite queries for PostgreSQL syntax, and update backup jobs that copy a SQLite file
Synapse version and platform floorSynapse 1.143.0 and later require PostgreSQL 14 or newerConfirm your Synapse release and choose a PostgreSQL major version that is still supported

Documented tools for the port

The port from SQLite to PostgreSQL rests on one Synapse script and a small set of database settings in homeserver.yaml. PostgreSQL's own upgrade and replication tools matter later, when the database is already in production, so the cards below separate what applies to the port from what applies afterward.

The synapse_port_db script

This is the documented path for copying a SQLite-backed Synapse database into PostgreSQL. It reads an offline copy of the SQLite file and writes into a PostgreSQL database you have already created, and it can be rerun against newer snapshots during the cutover. It does not change the homeserver configuration, move media files or repair a database that was already damaged by a VACUUM. Confirm the script's exact invocation for your Synapse release in the Postgres guide before you schedule the work.

Synapse Postgres guide

Synapse PostgreSQL setup guide

The Synapse Postgres guide sets out the database user, the database encoding and collation, and the server version Synapse expects. Check these before the script runs, because a database created with the wrong locale or an unsupported PostgreSQL version fails late. Read the guide against the Synapse release you run, since minimum PostgreSQL versions change between releases.

Minimum PostgreSQL version
14
Synapse Postgres guide

The database section of homeserver.yaml

After the port, the database block in homeserver.yaml must name the psycopg2 driver and carry the host, database name, user and password. The args keys set connection details, and a wrong cp_min or cp_max setting can exhaust connections under load. Keep the file readable only by the Synapse service account, and test a restart in a staging copy before you rely on these keys in production.

Synapse Postgres guide

pg_dump and pg_dumpall

These PostgreSQL tools export a database for backup or restore, and they fit the port only as a safety net. Take a dump of the new PostgreSQL database after the cutover so you can restore it on a fresh host if the first attempt fails. They do not convert SQLite data, so they are not a substitute for synapse_port_db. Use the PostgreSQL upgrading documentation for the exact commands that suit your version.

PostgreSQL upgrading docs

pg_upgrade and logical replication

pg_upgrade and logical replication move an existing PostgreSQL cluster to a newer major version, and they do not apply to the SQLite port itself. They become relevant once Synapse runs on PostgreSQL and you plan a major upgrade later. Logical replication works between major versions and can reduce downtime to several seconds, but it needs separate planning for schema and sequence handling. Confirm which path suits your data size and version gap before you schedule that work.

Logical replication downtime
Several seconds
PostgreSQL upgrading docs

Which tool to use when

Use synapse_port_db for the SQLite move, the Synapse Postgres guide for connection and version checks, and the homeserver.yaml keys for runtime settings. Reach for pg_dump or pg_upgrade only after the homeserver is stable on PostgreSQL. Ask your implementation partner which tools they will run, who holds backup copies, and how each step is recorded for your change log.

The two-phase sequence with a parallel run and cutover

The sequence keeps the SQLite server live while a PostgreSQL copy is built and checked, so the outage is limited to a final delta port and restart. The result is a validated PostgreSQL homeserver and a SQLite file kept for rollback until the retention period ends.

  1. Inventory the homeserver and provision PostgreSQL

    The Synapse operator records the current Synapse version, the database file path, media store size and the homeserver.yaml settings, then confirms the Synapse release supports the planned PostgreSQL version. The database platform team provisions a PostgreSQL instance in the client's infrastructure with a database and role for Synapse, and confirms the locale and encoding match the Synapse documentation. Done when a test connection from the Synapse host succeeds and the inventory is stored with the change record.

  2. Take an offline snapshot of the SQLite database

    Copy the SQLite database file to a separate working location while Synapse is running, so the live file stays untouched. Confirm the copy is complete by checking its size and integrity against the source. Done when the snapshot is in a location the port run can read and the operator has recorded its timestamp.

  3. Run the first port to a test PostgreSQL instance

    Run the synapse_port_db script against the snapshot with a configuration that points to the test PostgreSQL database. The script checks that auto_vacuum is disabled on the SQLite file, so the operator should confirm the result before starting. Done when the script finishes without errors and its output is saved with the run log.

  4. Validate the test copy before any cutover

    Start a test Synapse instance on the PostgreSQL copy with a non-production server name or an isolated network, then check logins, room history, device lists and media references against the source. Compare row counts or sample records that the team agrees on in advance. Done when the team signs off a written checklist and the known differences are documented.

  5. Port newer snapshots during the parallel run

    While the SQLite server keeps serving users, repeat the port against newer snapshots as often as the team needs. The script can be run repeatedly and can be killed and restarted safely, so an interrupted run is not a reason to start over. Do not VACUUM the SQLite database between runs, because the Synapse docs warn that this breaks the port. Done when the most recent snapshot is ported and the team has a timed plan for the shutdown.

  6. Shut down, port the final delta and restart on PostgreSQL

    Stop the Synapse process, take a final snapshot, and run the port script once more to carry over data written since the previous snapshot. Update the configuration to use PostgreSQL, then start Synapse and confirm it runs without database errors. Done when the homeserver serves a test login and a message exchange on PostgreSQL and the SQLite file is kept unchanged.

  7. Retain the SQLite file, then decommission it

    Keep the original SQLite database and the snapshots for the retention period set in the change plan, since rolling back a Synapse upgrade can be difficult and the same caution applies to a move that changes the database. Monitor logs and PostgreSQL disk use during this period, because the database may take 25% to 100% more disk space after porting. Done when the retention period ends, a final backup of PostgreSQL is verified and the SQLite file is removed under a signed-off record.

Why VACUUM on the SQLite file breaks the second pass

The SQLite database must stay untouched between port runs. Running VACUUM on the source file, or turning on auto_vacuum, can rearrange the pages and internal layout of the database so that the second pass of synapse_port_db no longer lines up with what the first pass already copied. The script is designed to run repeatedly against newer snapshots, and that design depends on the source being stable between runs. Treat the SQLite file as read-only from the first snapshot until the server is running on PostgreSQL.

Before the first run, check the auto_vacuum setting on the SQLite file and confirm it is disabled, since the script checks for this and will refuse to proceed if it is enabled. Record the result in your migration runbook so the check is repeatable for each pass. Also confirm that no scheduled job, backup tool or administrator script runs VACUUM against the database file, and disable any that do for the duration of the migration window. The Synapse docs: Using Postgres page is the reference to confirm the current wording of these warnings for your Synapse version.

Schedule any database maintenance, cleanup or tuning outside the migration, and finish it before the first snapshot is taken. If maintenance is needed in the middle of the migration, the safer path is to restart the whole port from a fresh snapshot rather than trust the incremental state. Ask your Synapse operator to write down who may touch the file, what jobs are paused, and how the team will confirm the file is unchanged before each rerun. These steps cost little, and they prevent a second pass from failing in ways that are hard to diagnose later.

What drives the effort and the disk space

This table lists the factors that change how long a SQLite to PostgreSQL port takes and how much disk the PostgreSQL server needs. Read each row as a driver, what pushes it up, and what to ask a partner to quote. The main takeaway is that database size and the event rate during the migration window shape most of the effort, and disk headroom should be planned before the snapshot is taken.

DriverWhat increases itWhat to ask a partner to quote
Database sizeA large SQLite file with years of room history, state events and media metadata means longer snapshot ports and longer delta runs.Estimated port time for a copy of your current database, measured on your hardware, and how the time repeats for each delta run.
Event rate during the windowA busy homeserver adds many events between the first snapshot and the cutover, so the second run has more to port.How the plan measures the delta from the first snapshot and what cutover window it assumes for your peak hours.
Disk headroomThe Synapse docs say the database may take 25% to 100% more disk space after porting, so PostgreSQL needs room beyond the SQLite file and its working copy.Disk sizing for the PostgreSQL volume, including the expected growth range from the docs and space for the snapshot and backups.
SQLite maintenance habitsRunning VACUUM on the SQLite file between port runs breaks the process, and the script checks that auto_vacuum is disabled. Any cleanup must be planned before the first snapshot.Confirmation that the plan avoids VACUUM on the source, and how the runbook checks auto_vacuum before each run.
PostgreSQL hosting and tuningA new PostgreSQL server with undersized memory, slow storage or no connection pooling adds time to the port and slows Synapse after cutover. Platform choices such as managed or self-run PostgreSQL also change the work.Hosting specification, tuning changes for Synapse, whether PgBouncer is included, and who owns patching and minor version updates.
PostgreSQL versionSynapse 1.143.0 and later require PostgreSQL 14 or newer. PostgreSQL 14 is supported until November 12, 2026, so the target version affects upgrade planning later.The target major version, its end-of-support date, and the plan for future major upgrades.
Backup and rollback planRolling back a Synapse upgrade can be difficult because of schema changes, and the SQLite file must be kept intact as the fallback. A longer retention period means more storage.Backup method for both databases, retention period, the tested restore steps, and the point at which the SQLite copy is kept.
Workers and RedisA Synapse deployment with workers needs Redis for replication, so the cutover touches every worker configuration and the Redis connection settings.Which worker processes and Redis settings change at cutover, and the test plan that checks replication after restart.
Team PostgreSQL skillsA team without PostgreSQL operations experience needs more review time for tuning, backups and failover, and may choose a managed service.Training or handover included in the scope, and which tasks the partner runs and which your staff run after handover.

Questions buyers ask before moving Synapse to PostgreSQL

How long is the downtime when moving Synapse from SQLite to PostgreSQL?

Downtime is the final cutover window, not the whole port. The two-phase approach ports an offline copy of the SQLite database first while Synapse keeps running, then stops the server only to rerun synapse_port_db for the data added since that snapshot and restart on PostgreSQL. The length of that window is set by how much data changed since the snapshot, how large the database is, how fast the storage and network are between the script and the PostgreSQL host, and how long it takes your team to verify the restart. No fixed duration applies to every server, so ask for a timed rehearsal on a copy of your own database before agreeing to a cutover window. Test on a copy first so the production window is predictable.

How much extra disk space does PostgreSQL need after the port?

Plan for the Synapse documentation's range: the database may take 25% to 100% more disk space after porting to PostgreSQL. The range is wide because the increase depends on your data mix, including how many events, state groups and indexes the server holds, and on how the database was previously stored and compacted in SQLite. Keep room for both copies during the migration, since the SQLite file and the PostgreSQL data directory exist at the same time, plus space for the snapshot and for WAL and backups. Measure your current database size and run the port against a copy to see where your own number lands.

Can our own team run synapse_port_db without a partner?

Yes, if your team can administer both Synapse and PostgreSQL, follow the upstream instructions, and rehearse the full sequence. The script is designed to be rerun against newer snapshots and safely killed and restarted, which makes a self-run migration workable. The risks lie in the surrounding steps: keeping the SQLite file untouched (the database must never be VACUUMed between runs, and the script checks that auto_vacuum is disabled), configuring PostgreSQL correctly for Synapse, and verifying the cutover. Decide based on whether your team has done this before and can cover the cutover window. Read the Synapse Postgres guide before deciding.

What does a partner need from our team to plan the migration?

A partner needs an accurate picture of your running system and the people who can approve changes. Expect requests for the Synapse version and configuration, the current SQLite database size and growth rate, the host and storage layout, the PostgreSQL version you plan to use, and the reverse proxy and federation setup. You should also name a change owner, confirm acceptable downtime windows, provide a test environment or permission to clone the database, and state how users are notified. Access should be limited to what the work needs and agreed in writing before work starts, since most engagements are fixed-scope.

Which PostgreSQL version should we pick, and how long will it be supported?

Choose a PostgreSQL major version that is still supported for the whole life of the deployment, and that your Synapse release accepts. Synapse 1.143.0 and later require PostgreSQL 14 or newer. Supported versions listed in the PostgreSQL versioning policy are 18 (final release November 14, 2030), 17 (to November 8, 2029), 16 (to November 9, 2028), 15 (to November 11, 2027) and 14 (to November 12, 2026). Version 14 is near end of support, so a new deployment should start on a newer major version. Confirm the current table on the PostgreSQL versioning policy page before you commit.

What does the migration cost depend on?

The cost is driven by the work, not by a published rate. Major components include discovery of your current configuration, the database size and how much it has grown, the number of environments needing rehearsal, the length of the cutover window and the staff who must be available for it, PostgreSQL host sizing and backup setup, and the post-cutover checks. Costs are one-time for the migration itself, while PostgreSQL hosting, backups, patching and monitoring recur. DeployOpen works from a written scope and provides a quote from it. Ask any provider to itemize these components and to state what is excluded.

What is the main risk if the migration goes wrong?

The main risk is a damaged or incomplete database after cutover, which can leave users unable to sign in or messages missing. Reduce it by keeping the original SQLite file intact, rehearsing the full sequence on a copy, and checking the restarted server against known rooms and accounts before reopening access. Rolling back can be difficult because of database schema changes between Synapse releases, so do not rely on reverting after a major upgrade. Keep verified backups of both databases through the window and agree a stop point in advance.

What usually goes wrong and how to prevent it

Most failed SQLite-to-PostgreSQL moves fail in predictable places: the source file changes between runs, the target host runs out of disk, versions don't line up, or the team skips checks before cutover. The cards below pair each risk with a prevention step you can plan before the maintenance window opens.

VACUUM or auto_vacuum on the SQLite file

The port script works only if the SQLite database stays as it was between snapshot runs. Running VACUUM on that file, or changing its auto_vacuum mode, can break the copy and force a fresh start. The script checks that auto_vacuum is disabled, so treat a failed check as a stop signal. Prevention: take a note of the file's state after each run, block maintenance jobs and admin scripts from touching the database, and document who may run VACUUM.

Synapse Postgres docs

Too little disk on the PostgreSQL host

PostgreSQL data can take noticeably more space than the SQLite file it replaces, so a host sized for the old database can fill during the port. A full disk stops the import and can leave the target in a state you must rebuild. Prevention: measure the current database and media growth, add headroom for the port and for the snapshot runs, and confirm free space on the data and WAL volumes before starting.

Extra disk space
25% to 100%

Synapse and PostgreSQL version mismatch

Synapse drops support for PostgreSQL versions once they reach upstream end of life, and recent Synapse releases require PostgreSQL 14 or newer. Installing an old PostgreSQL package on the new host can block the upgrade or the first start. Prevention: choose the Synapse release you will run, check its PostgreSQL floor in the upgrade notes, and pick a PostgreSQL major version that is still supported through your planned operating window.

Synapse upgrade notes

Skipped validation before cutover

Teams sometimes switch the configuration to PostgreSQL once the script finishes, without checking that users, rooms and events arrived intact. Problems then surface after users have already written to the new database, which makes rollback hard. Prevention: before cutover, compare row counts and sample rooms, log in as test accounts, send and receive messages across federation, and write down the checks and who signs off on them.

Media files left out of the plan

The port moves database rows, not the media store. Avatars, uploaded files and cached remote media live on disk or in object storage and are referenced by the database. If the media path or backup is missing from the plan, users see broken images and files after cutover. Prevention: inventory the media directory and its size, keep the media path in the new configuration, and test that an existing upload opens after the move.

Losing the signing key or server_name

Synapse's signing key and server_name identify the homeserver to other servers and anchor every user and room ID. Restarting on a new host with a regenerated key or a changed server_name breaks federation trust and identity. Prevention: copy the signing key file and the existing configuration unchanged, store a backup of both before any restart, and confirm the server_name value matches what federated servers already know.

How the snapshot ports and the final cutover fit together

The port starts from a read-only copy of the live SQLite file, so the running server is never the source of a half-written snapshot. The first synapse_port_db run loads that snapshot into PostgreSQL while the server keeps serving users. At cutover, Synapse is stopped, the script runs once more for data added since the snapshot, and the server restarts on PostgreSQL. Before restarting, check that the delta run completed without errors and that the SQLite file was not VACUUMed.

Two-phase port: a snapshot load while live, then a short delta run during shutdown.

What to check after Synapse runs on PostgreSQL

Once Synapse is running on PostgreSQL, the first job is to prove the server is healthy before anyone calls the cutover finished. Confirm the process starts cleanly, that clients can log in and sync, and that federation works both ways by joining a test room from a remote server and checking that remote users can see events from yours. Watch the logs for database errors during the first hours of traffic, since background database updates and any schema changes will show up there first.

Next, compare counts between the source and the new database. Check that the number of local users, rooms and devices in PostgreSQL matches the SQLite snapshot plus the delta you ported during the final pass. Small differences are expected if users were active between the two steps, so record the timestamp of the final run and reconcile against it. Any unexplained gap is a reason to stop and investigate before you retire the old server. Do not run VACUUM against the SQLite file while you compare, because the port script depends on it staying untouched.

Keep the SQLite file and its configuration until your rollback window closes, and write down that date. The Synapse upgrade notes warn that rolling back can be difficult because of database schema changes between releases, so a PostgreSQL cutover is not a simple revert path once Synapse has started writing new data. Plan backups of the PostgreSQL database, media store and signing key from the first day, and confirm restores work on a separate host. Also schedule routine PostgreSQL maintenance: minor releases with a restart, and a major version plan that respects the support end dates in the PostgreSQL versioning policy. Ask your team which PostgreSQL version your deployment will run and when it leaves support.

How DeployOpen scopes and delivers a Synapse PostgreSQL migration

DeployOpen approaches a move off SQLite as a planned change to a production homeserver, not a single script run. We scope the two-phase port, the cutover window, the disk headroom PostgreSQL needs and the handover to your team, with every step agreed in writing before work starts.

How we scope

  • Written scope covers the current Synapse version, the SQLite file size and the planned PostgreSQL host.
  • We confirm the auto_vacuum setting and any maintenance jobs that might run VACUUM against the SQLite file.
  • The quote states the disk space we will check against, the cutover window and who approves it.

How we build

  • We rehearse the synapse_port_db snapshot run on a copy and record the timing and any errors.
  • We verify the PostgreSQL version against the Synapse release notes before creating the target database.
  • We test the final cutover on a staging copy, including media paths, federation settings and the restart sequence.

How we hand over

  • You receive the runbook for the snapshot, delta and restart phases, with the rollback limits written down.
  • We document the PostgreSQL connection settings, backup job and the post-migration checks we ran.
  • Your team gets a walkthrough of disk growth monitoring so the 25% to 100% increase is tracked after cutover.

How we support

  • Engagements are fixed-scope, so any change to the database host or Synapse version is scoped separately.
  • Ongoing support, upgrades and PostgreSQL maintenance are available as a retainer after the handover.
  • Ask us to confirm how post-cutover issues are reported, triaged and retested before you sign.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.