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
1=== modified file 'database/schema/fti.py'
2--- database/schema/fti.py 2013-01-07 02:40:55 +0000
3+++ database/schema/fti.py 2019-03-05 13:27:34 +0000
4@@ -11,9 +11,7 @@
5
6 import _pythonpath
7
8-from distutils.version import LooseVersion
9 from optparse import OptionParser
10-import os.path
11 import sys
12 from textwrap import dedent
13
14@@ -240,19 +238,6 @@
15 return True
16
17
18-def get_pgversion(con):
19- rows = execute(con, r"show server_version", results=True)
20- return LooseVersion(rows[0][0])
21-
22-
23-def get_tsearch2_sql_path(con):
24- major, minor = get_pgversion(con).version[:2]
25- path = os.path.join(
26- PGSQL_BASE, '%d.%d' % (major, minor), 'contrib', 'tsearch2.sql')
27- assert os.path.exists(path), '%s does not exist' % path
28- return path
29-
30-
31 # Script options and arguments parsed from the command line by main()
32 options = None
33 args = None
34
35=== modified file 'database/schema/unautovacuumable.py'
36--- database/schema/unautovacuumable.py 2014-01-15 10:46:59 +0000
37+++ database/schema/unautovacuumable.py 2019-03-05 13:27:34 +0000
38@@ -18,7 +18,6 @@
39
40 import _pythonpath
41
42-from distutils.version import LooseVersion
43 from optparse import OptionParser
44 import sys
45 import time
46@@ -52,31 +51,19 @@
47 con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
48 cur = con.cursor()
49
50- cur.execute('show server_version')
51- pg_version = LooseVersion(cur.fetchone()[0])
52-
53 log.debug("Disabling autovacuum on all tables in the database.")
54- if pg_version < LooseVersion('8.4.0'):
55- cur.execute("""
56- INSERT INTO pg_autovacuum
57- SELECT pg_class.oid, FALSE, -1,-1,-1,-1,-1,-1,-1,-1
58- FROM pg_class
59- WHERE relkind in ('r','t')
60- AND pg_class.oid NOT IN (SELECT vacrelid FROM pg_autovacuum)
61- """)
62- else:
63- cur.execute("""
64- SELECT nspname,relname
65- FROM pg_namespace, pg_class
66- WHERE relnamespace = pg_namespace.oid
67- AND relkind = 'r' AND nspname <> 'pg_catalog'
68- """)
69- for namespace, table in list(cur.fetchall()):
70- cur.execute("""
71- ALTER TABLE ONLY "%s"."%s" SET (
72- autovacuum_enabled=false,
73- toast.autovacuum_enabled=false)
74- """ % (namespace, table))
75+ cur.execute("""
76+ SELECT nspname,relname
77+ FROM pg_namespace, pg_class
78+ WHERE relnamespace = pg_namespace.oid
79+ AND relkind = 'r' AND nspname <> 'pg_catalog'
80+ """)
81+ for namespace, table in list(cur.fetchall()):
82+ cur.execute("""
83+ ALTER TABLE ONLY "%s"."%s" SET (
84+ autovacuum_enabled=false,
85+ toast.autovacuum_enabled=false)
86+ """ % (namespace, table))
87
88 log.debug("Killing existing autovacuum processes")
89 num_autovacuums = -1
90
91=== modified file 'lib/lp/services/database/__init__.py'
92--- lib/lp/services/database/__init__.py 2015-10-14 15:22:01 +0000
93+++ lib/lp/services/database/__init__.py 2019-03-05 13:27:34 +0000
94@@ -15,7 +15,6 @@
95 DisconnectionError,
96 IntegrityError,
97 )
98-from storm.store import Store
99 import transaction
100 from twisted.python.util import mergeFunctionMetadata
101
102@@ -27,16 +26,7 @@
103
104 def activity_cols(cur):
105 """Adapt pg_stat_activity column names for the current DB server."""
106- if isinstance(cur, Store):
107- ver_str = cur.execute("SHOW server_version").get_one()
108- else:
109- cur.execute("SHOW server_version")
110- ver_str = cur.fetchone()
111- ver = tuple(map(int, ver_str[0].split('.')[:2]))
112- if ver < (9, 2):
113- return {'query': 'current_query', 'pid': 'procpid'}
114- else:
115- return {'query': 'query', 'pid': 'pid'}
116+ return {'query': 'query', 'pid': 'pid'}
117
118
119 def retry_transaction(func):
120
121=== modified file 'test_on_merge.py'
122--- test_on_merge.py 2018-05-14 13:11:14 +0000
123+++ test_on_merge.py 2019-03-05 13:27:34 +0000
124@@ -60,20 +60,10 @@
125 # Sanity check PostgreSQL version. No point in trying to create a test
126 # database when PostgreSQL is too old.
127 con = psycopg2.connect('dbname=template1')
128- cur = con.cursor()
129- cur.execute('show server_version')
130- server_version = cur.fetchone()[0]
131- try:
132- numeric_server_version = tuple(map(int, server_version.split('.')))
133- except ValueError:
134- # Skip this check if the version number is more complicated than
135- # we expected.
136- pass
137- else:
138- if numeric_server_version < (8, 0):
139- print 'Your PostgreSQL version is too old. You need 8.x.x'
140- print 'You have %s' % server_version
141- return 1
142+ if con.server_version < 90300:
143+ print 'Your PostgreSQL version is too old. You need at least 9.3.x'
144+ print 'You have %s' % con.get_parameter_status('server_version')
145+ return 1
146
147 # Drop the template database if it exists - the Makefile does this
148 # too, but we can explicity check for errors here