Fixing Synapse PostgreSQL collation and locale errors on a running homeserver
When Synapse refuses to start because its PostgreSQL database was created with a COLLATE or CTYPE setting it does not accept, the usual fix is to dump the data, recreate the database with the required locale settings, and restore it. Changing the locale of an existing database in place is possible in some cases but carries more risk, so most teams choose the dump and recreate route, especially when the error appears after a new PostgreSQL install or a migration. Synapse needs its database created with C collation and C CTYPE, and the error is a sign that the database was built with a different locale, often the default of a new operating system image or cluster initialization.
The first step is to confirm the mismatch before changing anything. Check the database settings with a read-only query on pg_database and compare them with what Synapse documents as required in its PostgreSQL setup notes. Then check the same settings on the cluster default, since new databases inherit it unless you specify otherwise. Confirm which PostgreSQL version and Synapse release you run, because Synapse 1.143.0 and later require PostgreSQL 14 or newer, and the Synapse upgrade notes describe how to read each release before you upgrade. Take a full backup first, and verify that the backup restores on a scratch host before you drop anything.
Bring in outside help when the homeserver holds data you cannot afford to lose, when the fix must happen inside a migration window with a fixed end date, or when federation, encryption keys and media all depend on a clean restore. An outside team can plan the dump, the restore order and the post-restore checks, and document the steps for your own operators. Ask any partner to state in writing which backups they will take, how they will prove the restore, and what downtime the plan assumes. Confirm those details with your own environment, since no duration is set here.
Choosing between dump and recreate and changing locale in place
When the homeserver is new, holds little data, or can be rebuilt from its configuration and a recent backup, the cleanest fix is to dump the existing data, drop the database, and recreate it with the correct LC_COLLATE and LC_CTYPE values before restoring. The database is created from scratch, so the locale is set once and nothing already stored has to be reinterpreted. The main trade-off is downtime and the need for a verified backup, because the restore only works if the dump is complete and the signing key, configuration and media are also safe.
- Downtime window: Synapse must be stopped while the dump is taken and restored, so plan a maintenance window with users informed.
- Backup first: Take a dump you have tested by restoring it to a scratch database before dropping anything.
- Template choice: Recreate the database from
template0with the locale you intend, because a default template can carry the wrong settings. - Config consistency: Keep the
databasesection ofhomeserver.yamlaligned with the new database name and credentials. - Dump route: PostgreSQL's upgrading guidance lists dump and restore as a supported route, so confirm the exact procedure for your PostgreSQL version.
Before you start, check that the restored database starts Synapse cleanly on a copy of the data.
When the database is large and users cannot be without the homeserver for long, a full dump and restore may be too slow to fit a window. Options are a dump and restore run on a standby or a second cluster with a planned cutover, or a logical replication approach that copies data into a new cluster with the correct locale. These routes shift effort from downtime to planning, testing and parallel infrastructure. The trade-off is that you run and verify two databases for a period, and you must confirm how Synapse behaves during the switch.
- Parallel cluster: Build a new PostgreSQL cluster with the correct locale and load it while the old one keeps serving.
- Replication route: PostgreSQL documents logical replication between major versions, which can shorten the cutover, but confirm it suits a locale change and your Synapse version.
- Cutover rehearsal: Practice the switch on a copy and time each step against your own limits.
- Write freeze: Decide how changes made after the copy starts will be captured before the final switch.
- Rollback plan: Keep the original cluster intact until the new one has run long enough to trust.
Before committing, ask your DBA to confirm the procedure against your PostgreSQL version and Synapse release.
When the wrong locale is discovered after the homeserver has been running and storing data, the database cannot simply be relabelled. Changing the collation or character type of an existing database in place is not a routine setting change, and it can leave indexes built under the old rules that behave differently under the new ones. Sorting, comparison and uniqueness checks may then return results that differ from what Synapse expects. The safer approach is usually to move the data into a correctly configured database, using the dump and recreate or cutover method, rather than attempting an in-place fix.
- Index risk: Indexes built under one collation may not match the rules applied later, so queries can return unexpected results.
- Data review: Check for rows whose ordering or uniqueness depends on the old locale before deciding.
- Scope of change: Determine whether the problem is limited to the database default or affects specific columns or tables.
- Recovery point: Confirm a current backup exists before any change, since in-place experiments can be hard to undo.
- Upstream guidance: Check the Synapse documentation and PostgreSQL release notes for your versions, and raise the question with Synapse maintainers if the situation is unusual.
Before acting, document what the database currently holds and agree the recovery path with the people who own the data.
Dump, recreate and restore the Synapse database
This sequence replaces a database with the wrong COLLATE or CTYPE by building a correctly configured PostgreSQL database and restoring Synapse data into it, with a check at each step so the team knows the new database is sound before Synapse uses it.
Confirm versions against the upgrade notes
Before touching data, the Synapse operator checks the installed Synapse release, its schema version and the PostgreSQL major version against the Synapse upgrade notes and the PostgreSQL versioning policy. Synapse 1.143.0 and later require PostgreSQL 14 or newer, so a cluster on an unsupported major version may need to move first. Record the results in the change ticket. The step is done when the team can name the Synapse version, the schema version and the target PostgreSQL version, and has confirmed the target is supported for that Synapse release.
Stop Synapse and all workers
The operator stops the main Synapse process and every worker so no writes reach the database during the dump. If Redis-based workers are in use, stop them in the same window so replication does not resume against a partial database. Confirm the processes have exited with the service manager or container runtime, not just that the web endpoint stopped answering. The step is done when no Synapse process is running on any host and the database has no active Synapse connections.
Take and verify a full backup
Take a full dump of the existing database, along with the homeserver configuration, the signing key and the media store, following your backup procedure. Use a logical dump that can be restored into a new database. Verify the dump by listing its contents or restoring it to a scratch cluster and checking row counts for key tables such as users and rooms. Store the copy off the database host. The step is done when a restore test has succeeded and the team has a second, independent copy of the data.
Create the new database with C collation
On a cluster the team has already checked, the operator creates a new database with the encoding, COLLATE and CTYPE that Synapse requires. Synapse documents the C locale for its database, so confirm that requirement in the current configuration manual and upgrade notes before creating the database. Then run a catalog query against pg_database to confirm the encoding, datcollate and datctype values. The step is done when the query output matches the required values exactly.
Restore the data into the new database
The operator restores the dump into the new database, using the same Synapse schema version that produced it. Watch the restore output for errors and keep the log with the change ticket. Then compare row counts for key tables and confirm the schema version matches the value recorded in the first step. The step is done when the restore finishes without errors and the counts and schema version match the source.
Point the configuration at the new database
The operator updates the database section of the Synapse configuration to reference the new database name, host and credentials, keeping the server_name and signing key unchanged. Check that the file is valid YAML and that the credentials are stored in the usual secret location. Only the database connection should change. The step is done when the configuration diff shows only the intended database settings, and the old database is left in place as a rollback point.
Start Synapse and read the logs
The operator starts the main process first, then the workers, and reads the startup logs as they appear. Look for the collation or locale error being gone and for any database migration messages. Confirm the health endpoint responds. The step is done when Synapse starts without the locale error and the logs show no repeated errors after startup finishes.
Test a login and a message
The operator signs in with a test account, sends a message in a test room and confirms a second test account receives it. If federation is in use, also confirm that the test room still resolves from another server. Keep the old database until these checks pass and the team has watched logs for a period agreed in the change plan. The step is done when login, message delivery and room access all work, and the team signs off the cutover.
Risks of changing collation or ctype in place
Altering a database's collation or character classification in place touches every index and every stored string at once. The cards below cover the risks that make a dump and recreate the safer default, and the check that reduces each one.
Index corruption from sort order changes
Indexes store values in the order the old collation defines. If the collation changes under them, lookups and range scans can return wrong results without any error. Before any change, list the indexes on Synapse tables that depend on text ordering and confirm with a PostgreSQL administrator how the database would be rebuilt. Do not assume existing indexes remain valid after a locale change.
Upgrading docsMandatory index rebuilds after change
Any in-place locale change means every affected index must be rebuilt before the database is trusted again. Ask the administrator to estimate rebuild time on a copy of your largest Synapse tables, and plan that work inside the maintenance window. Rebuilds also need free disk space, so check storage headroom before starting.
Mixed-locale data during partial change
If a change stops partway, some objects or databases may use the new locale and others the old one. Synapse can then compare the same strings in different ways depending on where they are read. Confirm with the team whether the change is one atomic step, and record the database locale for every database in the cluster before and after.
No clean rollback path
Reverting a locale change means running the same rebuild in reverse, which is slow and can fail partway through. Unlike a configuration rollback, the database state cannot simply be restored to its previous form. Treat the dump taken before the change as the only dependable way back, and test that the dump restores into a separate instance.
Backups taken under the old setting
Backups record the locale they were created under. A dump taken before the change must be restored into a cluster created with the target locale, and the restored data is only as good as that dump. Keep the pre-change dump and the matching configuration together, label them with the old locale, and verify a restore before deleting older copies.
Maintenance window requirements
Synapse should be stopped or kept out of write traffic while indexes are rebuilt and data is restored, so the window covers both the change and the verification. Agree the window length with the service owners using measured rebuild times from a rehearsal, not an estimate. Plan a go or no-go check before the window opens and a documented way to bring Synapse back online.
Checking a new PostgreSQL cluster before migration
Before Synapse moves onto a new PostgreSQL cluster, confirm that the cluster can create the database Synapse needs. Start with the cluster's default locale settings, which are fixed when the cluster is initialized. Check the LC_COLLATE and LC_CTYPE values reported for the template databases, and confirm that the template0 settings are the ones you intend to use. Ask the platform team or database provider to confirm how the cluster was initialized, because the default locale cannot be changed later without rebuilding the cluster. Then create a throwaway database with explicit COLLATE and CTYPE values set to C and UTF8, and record the results so the staging test has a known baseline.
Next, check the PostgreSQL version against the floor in the Synapse upgrade notes. Synapse 1.143.0 and later require PostgreSQL 14 or newer, and PostgreSQL 14 reaches end of support on November 12, 2026 according to the PostgreSQL versioning policy. A cluster on 14 therefore meets the Synapse floor but has a short remaining support window, so plan the next major version before you commit. Confirm the Synapse version you run against the current upgrade notes, since the floor changes with releases.
Run Synapse against the throwaway database in a staging environment before any production cutover. Let it complete its schema setup and background database updates, then check the startup log for collation or ctype errors and confirm that a sample of users, rooms and sync requests behaves as expected. Note that the migration method changes the locale risk. A dump and restore recreates the database with the locale you specify, pg_upgrade keeps the existing cluster's locale, and logical replication copies data into a database you create beforehand, so the target database's locale must be set correctly in advance. Confirm each method's locale behavior with your database team and test the one you plan to use.
Security and operational considerations during the fix
A dump and recreate moves every room, user record and credential through a temporary state. The cards below cover what must be protected, stopped, logged and verified so the rebuilt homeserver behaves like the one it replaces.
Protect the dump file
A PostgreSQL dump of a Synapse database holds room events, user records, access tokens and device data, so it is as sensitive as the live database. Write it to an encrypted volume with restricted file permissions, keep it off shared scratch space, and delete it only after the restored server has passed checks. Confirm with your own retention policy how long the dump may exist and who may copy it.
Back up the signing key and config
A database dump alone does not restore a Synapse homeserver. The signing key and the homeserver configuration file must be copied with the database, because the signing key identifies your server to other servers and must not change during the rebuild. Store copies together under the same access controls as the dump, and record their checksums so you can prove the copies match what Synapse was running.
Recreate the restricted database role
Synapse should connect with a dedicated PostgreSQL role that owns or can write only to its own database, not a superuser. When you recreate the database, create the role again with the same privileges, set the password from your secrets store rather than from a shell history, and confirm the role can connect before Synapse starts. Check that no credentials were written into the dump's restore commands in plain text.
Keep Synapse stopped during restore
Stop the Synapse process and any workers before you dump, and keep them stopped until the restore finishes and the data checks pass. If Synapse runs during the restore, it can write new events or media records into a half-loaded database, which makes the result hard to reason about and harder to roll back. Confirm the stop with the process manager, not only by a clean dump.
Log who ran the migration
Record the operator, the start and end times, the source and target PostgreSQL versions, the locale settings before and after, and the Synapse version in use. Keep this log with the change record. The Synapse upgrade notes warn that rolling back can be difficult after schema changes, so a clear record of what was changed and when helps your team decide how to recover if a later problem appears.
Verify federation and encrypted history
After the restore, confirm that other servers can still reach yours by checking delegation and the federation listener, then check that encrypted rooms still decrypt for existing users. Federation depends on the signing key and the server name remaining unchanged. Test with a room on a remote server and a user who holds existing encrypted history, and record the results before you close the change.
Synapse federation docsQuestions teams ask before fixing the locale themselves
How much effort and cost does a locale fix involve?
The effort depends on how much data must be moved, how long the service can stop, and how many processes depend on the database. Cost has two parts: internal engineering time for planning, rehearsal and the cutover, and any external help you buy. The main drivers are database size, the length of the downtime window you can accept, the number of Synapse workers that must be stopped and started, and whether you have a staging copy to rehearse on. A quote should itemize the dump and restore, validation, staging rehearsal, cutover and rollback plan separately, so you can see what is one-time and what recurs if you later want ongoing support.
Can an in-house team fix Synapse locale errors alone?
Yes, if the team has someone who has administered PostgreSQL and Synapse before, can read the upgrade and configuration documentation closely, and can run a rehearsal on a copy of production data. The work itself is a standard dump and recreate, but mistakes tend to happen in the surrounding steps: stopping every Synapse process, confirming the new database uses the required collation and character type, restoring with the correct owner and privileges, and checking the server starts cleanly. If no one on the team has done a database restore under time pressure, a short external review of the runbook is often a cheaper way to reduce risk than a full engagement.
What does the work need from our team?
Expect to provide five things: read-only or administrative access to the PostgreSQL server and the Synapse host, a current and verified backup that the team can restore elsewhere, a maintenance window agreed with the people who depend on the server, a staging environment or spare host for rehearsal, and a named approver who can decide to proceed or roll back. Access should be scoped to this task and removed afterward. The approver matters most during cutover, when someone must own the go or no-go call without waiting for a committee.
How long does the fix take?
Duration depends on database size, the restore speed of your hardware, the time needed to rebuild indexes and verify data, the downtime window you agree, and how many rehearsals the risk level justifies. A small test database can be rehearsed in a short session, while a large production database needs a dump and restore run timed on realistic hardware before a date is set. Ask any partner to show how they timed their rehearsal and to separate restore time from validation and communication time. Do not accept a duration that is not tied to a measured dump and restore on a copy of your data.
Is changing the locale in place ever advisable?
Changing collation or character type on an existing database is generally not a simple setting you can flip, and it is risky because existing indexes that depend on collation can become inconsistent with the data. PostgreSQL's own upgrade and maintenance guidance treats this as a rebuild problem rather than an in-place edit. For most Synapse deployments, the safer path is to dump the database, create a new one with the correct settings, restore into it and validate. In-place changes might be considered only after a specialist has reviewed your PostgreSQL version and indexes, and only with a tested backup and a rollback plan you have actually exercised.
Do we need to check a new PostgreSQL cluster before migrating Synapse to it?
Yes. Before pointing Synapse at a new cluster, confirm the database was created with the collation and character type that Synapse requires, that the server version meets the current Synapse requirements, and that the restored schema matches the expected version. Then start Synapse against a copy, watch its startup logs for locale or collation errors, and run a few representative checks such as logging in, sending a message and reading room history. Check the Synapse upgrade notes for the PostgreSQL version floor before choosing the target version, because a newer Synapse release can require a newer PostgreSQL.
What should we ask a partner to include in a written quote?
Ask for a written scope that names the systems covered, the steps in order, and the deliverables, such as a runbook, a rehearsal report and a rollback procedure. The quote should state which tasks are one-time, which recur, what each depends on (database size, number of workers, staging availability), and what the client must provide. Ask how the partner validates the restored database and what evidence you receive at the end. Confirm who holds credentials after the engagement, how the approver is involved, and what happens if the rehearsal reveals a larger problem than expected. DeployOpen works from a written scope, so ask for the scope before any price discussion.
Decision path from error to verified fix
The path starts at the Synapse startup error that reports a database with the wrong COLLATE or CTYPE, then checks the existing database settings before choosing between a rebuild on a new PostgreSQL cluster and an in-place locale change. Both branches end in a verified backup, a restore or change, a Synapse startup test and a federation check. Retire the old database only after those checks pass, because the dump and restore step is the one that cannot be undone if skipped.
Decision path from the startup error to a verified fix and retirement of the old database.
How DeployOpen scopes and delivers this fix
DeployOpen approaches a Synapse collation or locale fix as a written, fixed-scope piece of work inside infrastructure you control. We confirm the current database locale, plan the dump and recreate path with you, rebuild the database on a checked cluster, and hand over the evidence so your team can run it.
How we scope
- Confirm the Synapse version, PostgreSQL version and current database COLLATE and CTYPE values before any change is proposed.
- Agree in writing which databases, hosts, backups and maintenance windows the fix covers and what stays out of scope.
- Set out the deliverables, timeline and acceptance checks in the written scope, with ongoing support available as a retainer.
How we build
- Take and verify a full backup of the Synapse database and configuration before any dump or recreate step runs.
- Rehearse the dump, recreate and restore on a non-production copy so the steps and expected Synapse startup output are proven first.
- Check the target PostgreSQL cluster's locale settings against the Synapse requirements before the production database is loaded.
How we hand over
- Provide a runbook with the exact commands, configuration keys and file names used for your environment.
- Document the verification results, including Synapse startup logs and database settings, so your team can repeat the check later.
- Walk your operators through the restore steps and the rollback limits that apply to your Synapse release.
How we support
- Retest the Synapse startup and a sample of application behavior after the fix, and record the results in the handover pack.
- Offer follow-up support for upgrades to PostgreSQL or Synapse, which can change how locale checks and dumps should run.
- Make ongoing support and periodic restore testing available under a retainer agreed in writing.

