Skip to content
Snippets Groups Projects
Unverified Commit 967b6948 authored by Erik Johnston's avatar Erik Johnston Committed by GitHub
Browse files

Change allow_unsafe_locale to also apply on new databases (#17238)

We relax this as there are use cases where this is safe, though it is
still highly recommended that people avoid using it.
parent d7198dfb
No related branches found
No related tags found
No related merge requests found
Change the `allow_unsafe_locale` config option to also apply when setting up new databases.
...@@ -242,12 +242,11 @@ host all all ::1/128 ident ...@@ -242,12 +242,11 @@ host all all ::1/128 ident
### Fixing incorrect `COLLATE` or `CTYPE` ### Fixing incorrect `COLLATE` or `CTYPE`
Synapse will refuse to set up a new database if it has the wrong values of Synapse will refuse to start when using a database with incorrect values of
`COLLATE` and `CTYPE` set. Synapse will also refuse to start an existing database with incorrect values `COLLATE` and `CTYPE` unless the config flag `allow_unsafe_locale`, found in the
of `COLLATE` and `CTYPE` unless the config flag `allow_unsafe_locale`, found in the `database` section of the config, is set to true. Using different locales can
`database` section of the config, is set to true. Using different locales can cause issues if the locale library is updated from cause issues if the locale library is updated from underneath the database, or
underneath the database, or if a different version of the locale is used on any if a different version of the locale is used on any replicas.
replicas.
If you have a database with an unsafe locale, the safest way to fix the issue is to dump the database and recreate it with If you have a database with an unsafe locale, the safest way to fix the issue is to dump the database and recreate it with
the correct locale parameter (as shown above). It is also possible to change the the correct locale parameter (as shown above). It is also possible to change the
......
...@@ -142,6 +142,10 @@ class PostgresEngine( ...@@ -142,6 +142,10 @@ class PostgresEngine(
apply stricter checks on new databases versus existing database. apply stricter checks on new databases versus existing database.
""" """
allow_unsafe_locale = self.config.get("allow_unsafe_locale", False)
if allow_unsafe_locale:
return
collation, ctype = self.get_db_locale(txn) collation, ctype = self.get_db_locale(txn)
errors = [] errors = []
...@@ -155,7 +159,9 @@ class PostgresEngine( ...@@ -155,7 +159,9 @@ class PostgresEngine(
if errors: if errors:
raise IncorrectDatabaseSetup( raise IncorrectDatabaseSetup(
"Database is incorrectly configured:\n\n%s\n\n" "Database is incorrectly configured:\n\n%s\n\n"
"See docs/postgres.md for more information." % ("\n".join(errors)) "See docs/postgres.md for more information. You can override this check by"
"setting 'allow_unsafe_locale' to true in the database config.",
"\n".join(errors),
) )
def convert_param_style(self, sql: str) -> str: def convert_param_style(self, sql: str) -> str:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment