PostgreSQL setup and tuning for Synapse

Set up the PostgreSQL database for a production Synapse homeserver with the correct locale, tuned memory and connection pool settings, and a clear decision on separate hosts or an operator.

On this page

PostgreSQL setup for Synapse: what the database needs before go-live

If you are standing up a production Synapse homeserver, PostgreSQL is the database to plan for. Synapse also supports SQLite, but the Synapse documentation recommends PostgreSQL for production, and the work in this section covers database creation, locale, memory tuning, connection pooling and where the database runs. Before go-live, confirm the PostgreSQL major version against the Synapse release you intend to deploy: Synapse 1.143.0 and later require PostgreSQL 14 or newer, and Synapse 1.142.0 and later require Python 3.10 or newer. Check the current Synapse Postgres documentation for the exact settings that apply to your release before you write any configuration.

Synapse stores almost everything that makes a homeserver work in its database: user accounts, device keys, room state and event history, access tokens, and the metadata behind media and federation. Media files are stored separately on disk, but the metadata that points to them lives in PostgreSQL, so the database is the element you cannot rebuild from configuration alone. Decide early who owns the database role, where backups are taken, and how a restore is tested. Upgrades add another reason to plan ahead: the upgrade notes warn that rolling back can be difficult because of schema changes between releases, so a tested backup taken before each upgrade is the practical recovery path.

Several choices shape the database before any tuning begins. Pick a PostgreSQL major version that is still in upstream support for the whole period you expect to run it, and confirm it against the Synapse upgrade notes, since Synapse drops support for PostgreSQL versions once they reach end of life. Then decide whether PostgreSQL runs on the same host as Synapse, on separate hardware, or under an operator. Each choice changes how you size memory, handle failover and schedule maintenance. Ask your database and platform teams to confirm these decisions in writing, because the locale, pooling and memory settings in the following sections depend on them.

Which PostgreSQL hosting model fits your homeserver

Running PostgreSQL on the same machine as Synapse is the simplest layout to build and reason about. Synapse and the database share CPU, memory and disk, so the team installing the homeserver also owns the database packages, the service, the backup job and any upgrade. This model suits a small, non-critical deployment where one administrator maintains both components and a restore can be tested on a spare host. The main risk is resource contention: a large database competes with Synapse for memory during busy periods, and a host failure takes both services down together.

  • Ownership: the Synapse operator also owns PostgreSQL packages, patching, backups and restores.
  • Resource sharing: memory settings such as shared_buffers must leave room for Synapse and the operating system.
  • Failure scope: a host or disk failure stops the homeserver and the database at the same time.
  • Failover: no standby exists by default, so recovery depends on restoring a backup to new hardware.
  • Upgrades: PostgreSQL minor and major upgrades share a maintenance window with Synapse upgrades.

Before choosing this model, confirm who will run restore tests and how long your organization can tolerate the homeserver being offline during a rebuild.

Configuration options and when each fits

This table lists the PostgreSQL memory and connection settings that Synapse documentation asks you to size, what each controls, and what it depends on. Read each row as a question to answer for your host, not as a value to copy, because the right numbers follow from your memory and Synapse process count.

SettingWhat it controlsWhat it depends on and what to confirm
shared_buffersPostgreSQL's shared memory cache for table and index pagesHost RAM and what else runs on the box. Confirm the starting value against the Synapse Postgres docs and your own monitoring of cache hit rates.
effective_cache_sizeThe planner's estimate of memory available for caching, including the OS file cacheTotal RAM left after the OS and other services. It is a planning hint, not an allocation, so confirm it reflects the whole host.
work_memMemory per sort or hash operation before spilling to diskConcurrent queries and operations per query, so it multiplies with connection count. Confirm headroom under peak Synapse load.
maintenance_work_memMemory for VACUUM, CREATE INDEX and similar maintenance tasksSize of the largest tables and index builds you run, plus how often maintenance overlaps with traffic. Confirm during upgrades that add indexes.
autovacuum_work_memMemory used by each autovacuum workerNumber of autovacuum workers and table churn. Synapse write-heavy tables make this worth checking against the upstream guidance.
Huge pagesUse of large memory pages for shared_buffers, reducing page table overheadLarge deployments and kernel configuration. Confirm the OS setting and the Synapse docs before enabling, since it needs host-level changes.
cp_min and cp_max (connection pool)Minimum and maximum open connections Synapse keeps to PostgreSQLNumber of Synapse processes and workers, since each opens its own pool. The Synapse example uses cp_min 5 and cp_max 10; confirm total connections stay under PostgreSQL's max_connections.

How to create the Synapse database with the right locale

This sequence produces a PostgreSQL database that Synapse can open at first start, with the role, encoding, collation and memory settings chosen before any data exists.

  1. Confirm the required encoding and collation

    Before running any command, open the Synapse Postgres documentation and note the database encoding and collation it requires for a new Synapse database, along with the minimum PostgreSQL version for your Synapse release. The Synapse upgrade notes state that Synapse 1.143.0 and later require PostgreSQL 14 or newer, so check that version against the PostgreSQL versioning policy. Record the answers in your change ticket. You know this step is done when the required encoding, collation and minimum version are written down and matched to the release you will deploy.

  2. Install a supported PostgreSQL major version

    The platform team installs a PostgreSQL major version that is still in its support window on the database host or cluster you control. Choose a version that the PostgreSQL versioning policy lists as supported on the day you build, and avoid versions that have reached end of life, since Synapse drops support for them too. Confirm the installed version by running the server version query as a superuser. You know this step is done when the query returns a supported major version and the service starts cleanly.

  3. Create the Synapse role and database

    A database administrator creates a dedicated login role for Synapse with a strong password stored in your secrets manager, then creates the Synapse database owned by that role. Use the encoding and locale values confirmed in the first step, and set the template to template0 so the new database is not built from a template with different settings. Avoid giving the Synapse role superuser rights. You know this step is done when the database appears in the database list with the expected encoding and the role owns it.

  4. Verify encoding and collation as the Synapse role

    Connect to the new database as the Synapse role, not as the superuser, so you test the same access path Synapse will use. Run a query against the pg_database catalog to show the encoding and collation, and compare the output with the values you recorded earlier. If either value differs, drop and recreate the database before Synapse stores any data, because changing collation on a populated database is harder. You know this step is done when the connected session shows the confirmed encoding and collation and the role can create tables in its schema.

  5. Apply memory and connection pool settings

    The database administrator sets shared_buffers, effective_cache_size, work_mem, maintenance_work_mem and autovacuum_work_mem in postgresql.conf, sized to the host memory you have allocated to PostgreSQL. The Synapse Postgres docs describe these as values to tune to the host, and they also mention huge pages for large deployments. Restart PostgreSQL if the change requires it, then confirm the active values with the SHOW command. You know this step is done when SHOW returns the values you set and the server restarts without errors in its log.

  6. Point homeserver.yaml at the database

    The Synapse operator edits the database section of homeserver.yaml to set the PostgreSQL driver, host, port, database name, user and password, and to add the connection pool values such as cp_min and cp_max. The Synapse Postgres docs show an example pool of cp_min 5 and cp_max 10, which is a starting point to confirm against your workload. Keep the password in a file or secret reference rather than in the config in plain text where your tooling allows it. You know this step is done when the file validates and no database values are left at placeholder text.

  7. Start Synapse and check the logs

    The operator starts Synapse, which creates its schema on first run, and watches the startup log for database errors such as encoding or collation complaints, authentication failures or missing extensions. Connect as the Synapse role and list the tables to confirm the schema was created. If the log reports an encoding or locale error, stop Synapse and correct the database before going further. You know this step is done when Synapse reports that it is listening, the logs contain no database errors, and the schema tables exist.

How Synapse uses PostgreSQL and why tuning matters

Synapse keeps nearly all of its persistent state in PostgreSQL, so the database is where most of its load and most of its tuning decisions land. Events that make up rooms are stored there, along with the current room state, device and account data, and the bookkeeping that lets clients sync. Synapse also runs background database updates after upgrades, which are schema and data changes that continue while the server is serving traffic. Before you size anything, confirm the PostgreSQL version your target Synapse release requires, because the Synapse Postgres documentation is the place where the recommended settings are documented. The point to hold onto is that the database is a shared dependency for every function the homeserver performs.

The workload grows with the number of rooms and with federation. A busy room with many members produces more events and more state changes to resolve, and every remote server that joins a room sends and requests events that Synapse must store and check. Growth is usually gradual, so the database that was adequate at launch can become the bottleneck without any single change looking dramatic. The memory settings the documentation suggests, including shared_buffers, effective_cache_size, work_mem, maintenance_work_mem and autovacuum_work_mem, should be set against the memory of the host that actually runs PostgreSQL, and against how much memory your other services leave free. Huge pages are suggested for large deployments only.

Pool sizing is where a multi-process layout can break things. Synapse workers connect to Redis, which relays replication between the main process and the workers, and each process can open its own database connections. The example pool in the documentation uses cp_min of 5 and cp_max of 10 per process, so the connection count the server can demand is the sum across every process, not the value in one file. Add up the pool maximums for all processes and compare the total with max_connections on the database server, leaving headroom for administrators and maintenance jobs. Confirm the exact pool keys for your release in the configuration manual before you change them.

Security and operational considerations for the Synapse database

The Synapse database holds every room, event and account record on the homeserver, so its access model, backups and upgrade path matter as much as its tuning. The cards below cover how to restrict who and what can reach PostgreSQL, how to keep recovery and patching under control, and what to confirm with your own team before go-live.

Choose the authentication method

PostgreSQL documents several client authentication methods, including password, certificate, LDAP, GSSAPI and PAM. For the Synapse role, use SCRAM password authentication or certificates and confirm the method in pg_hba.conf for each database and user. MD5 password authentication is deprecated in PostgreSQL 18, so an MD5 entry carried over from an older template should be removed before you upgrade to that release.

PostgreSQL authentication methods

Restrict network access to Synapse hosts

Limit the listen_addresses setting and pg_hba.conf entries so only the Synapse hosts and approved administrative hosts can open connections on the PostgreSQL port. Keep the database off any public interface and off the same network segment as user-facing services where your design allows. Confirm the allowed source addresses with your network team and record them in the change log.

Separate admin and application roles

Create the Synapse application role with rights only to its own database, and keep superuser and schema-owner accounts for maintenance tasks such as upgrades and restores. Synapse needs to create and alter its own schema during upgrades, so confirm which role performs migrations and which role serves traffic. Rotate the admin credentials on a schedule your security team sets and store them in your secrets manager.

Encrypt and archive backups

Continuous archiving with WAL files is what makes point-in-time recovery possible. Encrypt base backups and archived WAL at rest and in transit, and store copies outside the Synapse host. Decide the retention window with your compliance team, because it determines how far back a restore can go and how long chat data persists in backups.

Continuous archiving docs

Test point-in-time recovery

A backup that has never been restored is not yet a recovery plan. Run a restore to a separate host at a chosen timestamp, start Synapse against the restored database in a non-production setting, and check that rooms and recent events load. Record how long the restore took and which steps needed manual work, and repeat the test after each change to the backup tooling.

Patch minor and major releases differently

Minor PostgreSQL releases never change the storage format, so updating means replacing executables and restarting the server. Major upgrades need a separate plan: pg_upgrade, a dump and restore, or logical replication, which can keep downtime to several seconds. Check Synapse's supported PostgreSQL versions before each major upgrade, since Synapse drops PostgreSQL versions once they reach upstream end of life.

Support per major version
5 years

How Synapse, its workers and PostgreSQL connect

The main Synapse process and its workers all register with Redis, which relays replication between them. Every process opens its own connection pool to the PostgreSQL primary, so the pool settings multiply across processes. An optional standby receives changes from the primary, and WAL archives go to a separate backup target. Check that only the Synapse hosts can reach the database network, and that the pool sizes you set on each process add up to less than the server's connection limit.

Synapse processes, Redis, the connection pool and PostgreSQL with its backup target.

Questions teams ask before setting up Synapse PostgreSQL

What drives the cost and effort of a PostgreSQL setup for Synapse?

The main drivers are where PostgreSQL runs, how many Synapse worker processes you plan to run, and what backup and failover you require. A single database on a host you already operate is a small job. Separate hardware, a high availability pair, point-in-time recovery and a tested restore each add design, build and verification work. Ask any provider to quote against a written scope that lists the hosting model, the worker count, the backup targets, the recovery objectives your team has agreed to, and whether an existing PostgreSQL operator is already in use. Cost is one-time for the build and tuning, and recurring for patching, backup verification and PostgreSQL upgrades, which the upstream project supports for five years per major version.

How long does Synapse PostgreSQL setup and tuning take?

Duration depends on scope rather than on a single number. Creating the database and tuning memory settings on an existing host is the shortest path. Adding separate hardware, replication, automated failover, connection pooling and restore testing lengthens the work, mostly because each component needs review and a recovery exercise. Sizing also takes time when the host's memory and the expected load are not yet known. Ask for a timeline tied to named milestones: environment review, database creation, configuration, load observation and sign-off. Engagements are normally fixed-scope, so the timeline should appear in the written agreement before work starts.

What does the work need from our team?

Expect to provide four things. First, access to the hosts or the Kubernetes cluster where PostgreSQL and Synapse will run, with rights to install packages or manage the operator. Second, the current Synapse configuration file and the Synapse version you run, because the database settings and the supported PostgreSQL floor depend on it. Third, backup targets, such as object storage or a backup server, with credentials and retention rules. Fourth, a named owner who signs off on the sizing and the recovery plan. Without the sign-off, tuning values stay untested against your real workload.

Can our internal team set up Synapse PostgreSQL alone?

Often yes for a single-node setup, if the team already runs PostgreSQL and understands the Synapse database requirements. The Synapse documentation covers creating the database with the C locale and the collation settings, plus the memory and connection pool parameters. The harder parts are a tested backup and restore, a failover design that someone has rehearsed, and upgrades across PostgreSQL major versions. Check whether your team has run those tasks before, and whether anyone will own them after launch. A quick internal review of the plan against the official Synapse Postgres guidance can show where help is needed.

When should we bring in a partner for this work?

Bring in a partner when the setup carries requirements your team has not delivered before, such as point-in-time recovery that must be proven, a high availability design across sites, compliance evidence for backups and access, or a migration from an existing database with a short window. A partner is also useful when the team is short on time for the build but can run the system afterward. DeployOpen plans, implements, hardens, backs up, upgrades and documents self-hosted platforms in infrastructure you control, including PostgreSQL, and works from a written scope. It does not issue audit reports or certifications.

What changes when PostgreSQL moves to a separate host or an operator?

A separate host adds network latency, a second set of patches, its own backups and firewall rules, and a clear boundary for memory sizing, since the Synapse host no longer shares RAM with the database. An operator such as CloudNativePG, which is Apache-2.0 licensed and a CNCF Sandbox project, manages persistent volume claims directly, handles failover through the Kubernetes API without external tools, and includes PgBouncer pooling and Barman Cloud backups. The trade-off is that your team must run Kubernetes well enough to operate the operator. Patroni is an alternative for non-Kubernetes environments, but it needs a distributed configuration store such as etcd or Consul. Confirm the operator version and PostgreSQL version in the release notes before you commit.

How does the PostgreSQL version affect a Synapse setup?

Synapse 1.143.0 and later require PostgreSQL 14 or newer, so the version you choose sets the floor for your upgrade path. PostgreSQL 14 is supported until November 12, 2026, and PostgreSQL 18, first released September 25, 2025, is supported until November 14, 2030. Choosing a version that is near end of life means a major upgrade is planned soon after launch. Minor releases do not change the storage format, so they can be applied by replacing executables and restarting, while major upgrades need pg_upgrade, a dump and restore, or logical replication. Plan the major version against both the Synapse floor and the PostgreSQL support window.

Keeping PostgreSQL current without breaking Synapse

The database version you run sets a deadline you cannot negotiate with Synapse. Synapse drops support for PostgreSQL versions once they reach upstream end of life, so a server that stays on an unsupported major version will eventually stop receiving compatible Synapse releases. PostgreSQL 14 is supported until November 12, 2026, while PostgreSQL 18, first released September 25, 2025, is supported until November 14, 2030. Before you commit to a version, check the current Synapse upgrade notes for the PostgreSQL floor of the release you plan to run, and put the end-of-life dates for your chosen major version on your patch calendar. Ask your database team which major version they will standardize on, since that decision determines how often you will have to upgrade.

Within a major version, minor releases are the low-risk path. They replace executables and restart the server without changing the internal storage format, so they fit a routine maintenance window. Major upgrades are a different exercise. Options include pg_upgrade, dump and restore with pg_dumpall, or logical replication, which can cut downtime to several seconds but needs careful setup and verification. Plan the major upgrade as a Synapse change, not only a database change, and confirm with Element's upgrade notes whether the Synapse release you run supports the target PostgreSQL version before you start.

Rolling back Synapse can be difficult because database schema changes between releases may not reverse cleanly, so the upgrade plan must include a restore point taken immediately before any Synapse or PostgreSQL change. Use a logical dump or a consistent base backup with tested restore steps, and record the Synapse version, configuration and PostgreSQL version alongside it. Rehearse the restore on a separate host, measure how long it takes, and confirm that Synapse starts and serves a known test account against the restored database. Do not treat a backup you have never restored as a restore point.

How DeployOpen scopes and delivers Synapse database work

DeployOpen plans, builds, documents and supports the PostgreSQL database behind a Synapse homeserver inside the client's own infrastructure, whether that is a cloud account, a data center or an air-gapped network. Work starts from a written scope that sets the database version, locale, sizing inputs, hosting model and handover items before any configuration changes.

How we scope

  • Confirm the PostgreSQL major version against the Synapse release you plan to run, since newer Synapse lines set minimum PostgreSQL floors.
  • Record the planned host memory, expected user count and hosting model so shared_buffers and pool sizing have a documented basis.
  • Agree in writing whether PostgreSQL stays on the Synapse host, moves to separate hardware or runs under an operator.

How we build

  • Create the Synapse database with the C locale settings the Synapse Postgres documentation requires, and verify them before first start.
  • Set shared_buffers, effective_cache_size, work_mem and maintenance settings against the measured host memory, then test the connection pool limits.
  • Configure backups, restore testing and monitoring for database growth as part of the same build, not as a later task.

How we hand over

  • Deliver a written configuration record with every changed setting, its reason and the host it applies to.
  • Provide a restore runbook and a tested recovery procedure, with the steps your team needs to repeat them without DeployOpen.
  • Document the upgrade path for PostgreSQL minor and major releases, including rollback limits, before handover is accepted.

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer, covering PostgreSQL and Synapse changes together.
  • Ask any partner for the written scope, the named deliverables and the handover list before comparing quotes.

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.