1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Sanity checks for the PostgreSQL database"""
9
from canonical.config import config
10
from canonical.database.sqlbase import connect
13
def confirmEncoding(*args, **kw):
14
'''Raise an exception, explaining what went wrong, if the PostgreSQL
15
database encoding is not UNICODE
17
subsribed to zope.app.appsetup.IProcessStartingEvent
20
con = connect(config.launchpad.dbuser)
23
dbname = config.database.dbname
25
'select encoding from pg_catalog.pg_database where datname=%s',
30
raise RuntimeError('Database %r does not exist or is not unique'
35
"Database %r is using the wrong encidong (%r). You need "
36
"to recreate your database using 'createdb -E UNICODE %s'" % (
37
dbname, res[0][0], dbname
43
def confirmNoAddMissingFrom(*args, **kw):
44
'''Raise a warning if add_missing_from is turned on (dangerous default).
46
This will become an error in the future. Subscribed to
47
zope.app.appsetup.IProcessStartingEvent
50
con = connect(config.launchpad.dbuser)
53
cur.execute('show add_missing_from')
55
if res[0][0] != 'off':
57
"Need to set add_missing_from=false in "
58
"/etc/postgresql/postgresql.conf"