Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Warn if postgres database has non-C locale. #6734

Merged
merged 11 commits into from
Jan 28, 2020
1 change: 1 addition & 0 deletions changelog.d/6734.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warn if postgrse database has a non-C locale, as that can cause issues when upgrading locales (e.g. due to upgrading OS).
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions synapse/storage/engines/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from ._base import IncorrectDatabaseSetup

logger = logging.getLogger(__name__)


class PostgresEngine(object):
single_threaded = False
Expand Down Expand Up @@ -52,6 +56,20 @@ def check_database(self, db_conn, allow_outdated_version: bool = False):
"See docs/postgres.rst for more information." % (rows[0][0],)
)

txn.execute(
"SELECT datcollate, datctype FROM pg_database WHERE datname = current_database()"
)
collation, ctype = txn.fetchone()
if collation != "C":
logger.warning(
"Database has incorrect collation of %r. Should be 'C'", collation
)

if ctype != "C":
logger.warning(
"Database has incorrect ctype of %r. Should be 'C'", ctype
)

def convert_param_style(self, sql):
return sql.replace("?", "%s")

Expand Down