← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/postgresql-version-checks into lp:launchpad.

Commit message:
Drop support for PostgreSQL < 9.3.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/postgresql-version-checks/+merge/363971

The one remaining use of "SHOW server_version;" now uses more future-proof constructions instead.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/postgresql-version-checks into lp:launchpad.
=== 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 @@
 
 import _pythonpath
 
-from distutils.version import LooseVersion
 from optparse import OptionParser
-import os.path
 import sys
 from textwrap import dedent
 
@@ -240,19 +238,6 @@
     return True
 
 
-def get_pgversion(con):
-    rows = execute(con, r"show server_version", results=True)
-    return LooseVersion(rows[0][0])
-
-
-def get_tsearch2_sql_path(con):
-    major, minor = get_pgversion(con).version[:2]
-    path = os.path.join(
-        PGSQL_BASE, '%d.%d' % (major, minor), 'contrib', 'tsearch2.sql')
-    assert os.path.exists(path), '%s does not exist' % path
-    return path
-
-
 # Script options and arguments parsed from the command line by main()
 options = None
 args = None

=== 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 @@
 
 import _pythonpath
 
-from distutils.version import LooseVersion
 from optparse import OptionParser
 import sys
 import time
@@ -52,31 +51,19 @@
     con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
     cur = con.cursor()
 
-    cur.execute('show server_version')
-    pg_version = LooseVersion(cur.fetchone()[0])
-
     log.debug("Disabling autovacuum on all tables in the database.")
-    if pg_version < LooseVersion('8.4.0'):
-        cur.execute("""
-            INSERT INTO pg_autovacuum
-            SELECT pg_class.oid, FALSE, -1,-1,-1,-1,-1,-1,-1,-1
-            FROM pg_class
-            WHERE relkind in ('r','t')
-                AND pg_class.oid NOT IN (SELECT vacrelid FROM pg_autovacuum)
-            """)
-    else:
-        cur.execute("""
-            SELECT nspname,relname
-            FROM pg_namespace, pg_class
-            WHERE relnamespace = pg_namespace.oid
-                AND relkind = 'r' AND nspname <> 'pg_catalog'
-            """)
-        for namespace, table in list(cur.fetchall()):
-            cur.execute("""
-                ALTER TABLE ONLY "%s"."%s" SET (
-                    autovacuum_enabled=false,
-                    toast.autovacuum_enabled=false)
-                """ % (namespace, table))
+    cur.execute("""
+        SELECT nspname,relname
+        FROM pg_namespace, pg_class
+        WHERE relnamespace = pg_namespace.oid
+            AND relkind = 'r' AND nspname <> 'pg_catalog'
+        """)
+    for namespace, table in list(cur.fetchall()):
+        cur.execute("""
+            ALTER TABLE ONLY "%s"."%s" SET (
+                autovacuum_enabled=false,
+                toast.autovacuum_enabled=false)
+            """ % (namespace, table))
 
     log.debug("Killing existing autovacuum processes")
     num_autovacuums = -1

=== 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 @@
     DisconnectionError,
     IntegrityError,
     )
-from storm.store import Store
 import transaction
 from twisted.python.util import mergeFunctionMetadata
 
@@ -27,16 +26,7 @@
 
 def activity_cols(cur):
     """Adapt pg_stat_activity column names for the current DB server."""
-    if isinstance(cur, Store):
-        ver_str = cur.execute("SHOW server_version").get_one()
-    else:
-        cur.execute("SHOW server_version")
-        ver_str = cur.fetchone()
-    ver = tuple(map(int, ver_str[0].split('.')[:2]))
-    if ver < (9, 2):
-        return {'query': 'current_query', 'pid': 'procpid'}
-    else:
-        return {'query': 'query', 'pid': 'pid'}
+    return {'query': 'query', 'pid': 'pid'}
 
 
 def retry_transaction(func):

=== 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 @@
     # Sanity check PostgreSQL version. No point in trying to create a test
     # database when PostgreSQL is too old.
     con = psycopg2.connect('dbname=template1')
-    cur = con.cursor()
-    cur.execute('show server_version')
-    server_version = cur.fetchone()[0]
-    try:
-        numeric_server_version = tuple(map(int, server_version.split('.')))
-    except ValueError:
-        # Skip this check if the version number is more complicated than
-        # we expected.
-        pass
-    else:
-        if numeric_server_version < (8, 0):
-            print 'Your PostgreSQL version is too old.  You need 8.x.x'
-            print 'You have %s' % server_version
-            return 1
+    if con.server_version < 90300:
+        print 'Your PostgreSQL version is too old.  You need at least 9.3.x'
+        print 'You have %s' % con.get_parameter_status('server_version')
+        return 1
 
     # Drop the template database if it exists - the Makefile does this
     # too, but we can explicity check for errors here


Follow ups