Skip to content

Commit 78dd7b4

Browse files
erikjohnstonH-Shay
authored andcommitted
Change allow_unsafe_locale to also apply on new databases (element-hq#17238)
We relax this as there are use cases where this is safe, though it is still highly recommended that people avoid using it.
1 parent f26862f commit 78dd7b4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Diff for: changelog.d/17238.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change the `allow_unsafe_locale` config option to also apply when setting up new databases.

Diff for: docs/postgres.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,11 @@ host all all ::1/128 ident
242242
243243
### Fixing incorrect `COLLATE` or `CTYPE`
244244
245-
Synapse will refuse to set up a new database if it has the wrong values of
246-
`COLLATE` and `CTYPE` set. Synapse will also refuse to start an existing database with incorrect values
247-
of `COLLATE` and `CTYPE` unless the config flag `allow_unsafe_locale`, found in the
248-
`database` section of the config, is set to true. Using different locales can cause issues if the locale library is updated from
249-
underneath the database, or if a different version of the locale is used on any
250-
replicas.
245+
Synapse will refuse to start when using a database with incorrect values of
246+
`COLLATE` and `CTYPE` unless the config flag `allow_unsafe_locale`, found in the
247+
`database` section of the config, is set to true. Using different locales can
248+
cause issues if the locale library is updated from underneath the database, or
249+
if a different version of the locale is used on any replicas.
251250
252251
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
253252
the correct locale parameter (as shown above). It is also possible to change the

Diff for: synapse/storage/engines/postgres.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def check_new_database(self, txn: Cursor) -> None:
142142
apply stricter checks on new databases versus existing database.
143143
"""
144144

145+
allow_unsafe_locale = self.config.get("allow_unsafe_locale", False)
146+
if allow_unsafe_locale:
147+
return
148+
145149
collation, ctype = self.get_db_locale(txn)
146150

147151
errors = []
@@ -155,7 +159,9 @@ def check_new_database(self, txn: Cursor) -> None:
155159
if errors:
156160
raise IncorrectDatabaseSetup(
157161
"Database is incorrectly configured:\n\n%s\n\n"
158-
"See docs/postgres.md for more information." % ("\n".join(errors))
162+
"See docs/postgres.md for more information. You can override this check by"
163+
"setting 'allow_unsafe_locale' to true in the database config.",
164+
"\n".join(errors),
159165
)
160166

161167
def convert_param_style(self, sql: str) -> str:

0 commit comments

Comments
 (0)