summary refs log tree commit diff
path: root/synapse/storage/engines/postgres.py
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-04-29 13:04:22 +0100
committerMark Haines <mjark@negativecurvature.net>2015-04-29 13:04:22 +0100
commit19167fd21fb74c10c95f61808d2b3c453ea36e8d (patch)
treed29e65d35d444b6e1b426fe44547585a2af2afcf /synapse/storage/engines/postgres.py
parentminimal doc (diff)
parentMake postgres database error slightly more helpful (diff)
downloadsynapse-19167fd21fb74c10c95f61808d2b3c453ea36e8d.tar.xz
Merge pull request #135 from matrix-org/erikj/postgres_charset_check
Check that postgres database has correct charset set
Diffstat (limited to 'synapse/storage/engines/postgres.py')
-rw-r--r--synapse/storage/engines/postgres.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/synapse/storage/engines/postgres.py b/synapse/storage/engines/postgres.py
index b8cca9b187..7125f66f01 100644
--- a/synapse/storage/engines/postgres.py
+++ b/synapse/storage/engines/postgres.py
@@ -15,12 +15,24 @@
 
 from synapse.storage import prepare_database
 
+from ._base import IncorrectDatabaseSetup
+
 
 class PostgresEngine(object):
     def __init__(self, database_module):
         self.module = database_module
         self.module.extensions.register_type(self.module.extensions.UNICODE)
 
+    def check_database(self, txn):
+        txn.execute("SHOW SERVER_ENCODING")
+        rows = txn.fetchall()
+        if rows and rows[0][0] != "UTF8":
+            raise IncorrectDatabaseSetup(
+                "Database has incorrect encoding: '%s' instead of 'UTF8'\n"
+                "See docs/postgres.rst for more information."
+                % (rows[0][0],)
+            )
+
     def convert_param_style(self, sql):
         return sql.replace("?", "%s")