Merge lp:~cjwatson/launchpad/postgresql-version-checks into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18890
Proposed branch: lp:~cjwatson/launchpad/postgresql-version-checks
Merge into: lp:launchpad
Diff against target: 148 lines (+17/-65)
4 files modified
database/schema/fti.py (+0/-15)
database/schema/unautovacuumable.py (+12/-25)
lib/lp/services/database/__init__.py (+1/-11)
test_on_merge.py (+4/-14)
To merge this branch: bzr merge lp:~cjwatson/launchpad/postgresql-version-checks
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+363971@code.launchpad.net

Commit message

Drop support for PostgreSQL < 9.3.

Description of the change

The one remaining use of "SHOW server_version;" now uses more future-proof constructions instead.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'database/schema/fti.py'
--- database/schema/fti.py 2013-01-07 02:40:55 +0000
+++ database/schema/fti.py 2019-03-05 13:27:34 +0000
@@ -11,9 +11,7 @@
1111
12import _pythonpath12import _pythonpath
1313
14from distutils.version import LooseVersion
15from optparse import OptionParser14from optparse import OptionParser
16import os.path
17import sys15import sys
18from textwrap import dedent16from textwrap import dedent
1917
@@ -240,19 +238,6 @@
240 return True238 return True
241239
242240
243def get_pgversion(con):
244 rows = execute(con, r"show server_version", results=True)
245 return LooseVersion(rows[0][0])
246
247
248def get_tsearch2_sql_path(con):
249 major, minor = get_pgversion(con).version[:2]
250 path = os.path.join(
251 PGSQL_BASE, '%d.%d' % (major, minor), 'contrib', 'tsearch2.sql')
252 assert os.path.exists(path), '%s does not exist' % path
253 return path
254
255
256# Script options and arguments parsed from the command line by main()241# Script options and arguments parsed from the command line by main()
257options = None242options = None
258args = None243args = None
259244
=== modified file 'database/schema/unautovacuumable.py'
--- database/schema/unautovacuumable.py 2014-01-15 10:46:59 +0000
+++ database/schema/unautovacuumable.py 2019-03-05 13:27:34 +0000
@@ -18,7 +18,6 @@
1818
19import _pythonpath19import _pythonpath
2020
21from distutils.version import LooseVersion
22from optparse import OptionParser21from optparse import OptionParser
23import sys22import sys
24import time23import time
@@ -52,31 +51,19 @@
52 con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)51 con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
53 cur = con.cursor()52 cur = con.cursor()
5453
55 cur.execute('show server_version')
56 pg_version = LooseVersion(cur.fetchone()[0])
57
58 log.debug("Disabling autovacuum on all tables in the database.")54 log.debug("Disabling autovacuum on all tables in the database.")
59 if pg_version < LooseVersion('8.4.0'):55 cur.execute("""
60 cur.execute("""56 SELECT nspname,relname
61 INSERT INTO pg_autovacuum57 FROM pg_namespace, pg_class
62 SELECT pg_class.oid, FALSE, -1,-1,-1,-1,-1,-1,-1,-158 WHERE relnamespace = pg_namespace.oid
63 FROM pg_class59 AND relkind = 'r' AND nspname <> 'pg_catalog'
64 WHERE relkind in ('r','t')60 """)
65 AND pg_class.oid NOT IN (SELECT vacrelid FROM pg_autovacuum)61 for namespace, table in list(cur.fetchall()):
66 """)62 cur.execute("""
67 else:63 ALTER TABLE ONLY "%s"."%s" SET (
68 cur.execute("""64 autovacuum_enabled=false,
69 SELECT nspname,relname65 toast.autovacuum_enabled=false)
70 FROM pg_namespace, pg_class66 """ % (namespace, table))
71 WHERE relnamespace = pg_namespace.oid
72 AND relkind = 'r' AND nspname <> 'pg_catalog'
73 """)
74 for namespace, table in list(cur.fetchall()):
75 cur.execute("""
76 ALTER TABLE ONLY "%s"."%s" SET (
77 autovacuum_enabled=false,
78 toast.autovacuum_enabled=false)
79 """ % (namespace, table))
8067
81 log.debug("Killing existing autovacuum processes")68 log.debug("Killing existing autovacuum processes")
82 num_autovacuums = -169 num_autovacuums = -1
8370
=== modified file 'lib/lp/services/database/__init__.py'
--- lib/lp/services/database/__init__.py 2015-10-14 15:22:01 +0000
+++ lib/lp/services/database/__init__.py 2019-03-05 13:27:34 +0000
@@ -15,7 +15,6 @@
15 DisconnectionError,15 DisconnectionError,
16 IntegrityError,16 IntegrityError,
17 )17 )
18from storm.store import Store
19import transaction18import transaction
20from twisted.python.util import mergeFunctionMetadata19from twisted.python.util import mergeFunctionMetadata
2120
@@ -27,16 +26,7 @@
2726
28def activity_cols(cur):27def activity_cols(cur):
29 """Adapt pg_stat_activity column names for the current DB server."""28 """Adapt pg_stat_activity column names for the current DB server."""
30 if isinstance(cur, Store):29 return {'query': 'query', 'pid': 'pid'}
31 ver_str = cur.execute("SHOW server_version").get_one()
32 else:
33 cur.execute("SHOW server_version")
34 ver_str = cur.fetchone()
35 ver = tuple(map(int, ver_str[0].split('.')[:2]))
36 if ver < (9, 2):
37 return {'query': 'current_query', 'pid': 'procpid'}
38 else:
39 return {'query': 'query', 'pid': 'pid'}
4030
4131
42def retry_transaction(func):32def retry_transaction(func):
4333
=== modified file 'test_on_merge.py'
--- test_on_merge.py 2018-05-14 13:11:14 +0000
+++ test_on_merge.py 2019-03-05 13:27:34 +0000
@@ -60,20 +60,10 @@
60 # Sanity check PostgreSQL version. No point in trying to create a test60 # Sanity check PostgreSQL version. No point in trying to create a test
61 # database when PostgreSQL is too old.61 # database when PostgreSQL is too old.
62 con = psycopg2.connect('dbname=template1')62 con = psycopg2.connect('dbname=template1')
63 cur = con.cursor()63 if con.server_version < 90300:
64 cur.execute('show server_version')64 print 'Your PostgreSQL version is too old. You need at least 9.3.x'
65 server_version = cur.fetchone()[0]65 print 'You have %s' % con.get_parameter_status('server_version')
66 try:66 return 1
67 numeric_server_version = tuple(map(int, server_version.split('.')))
68 except ValueError:
69 # Skip this check if the version number is more complicated than
70 # we expected.
71 pass
72 else:
73 if numeric_server_version < (8, 0):
74 print 'Your PostgreSQL version is too old. You need 8.x.x'
75 print 'You have %s' % server_version
76 return 1
7767
78 # Drop the template database if it exists - the Makefile does this68 # Drop the template database if it exists - the Makefile does this
79 # too, but we can explicity check for errors here69 # too, but we can explicity check for errors here