Alter postgres options on the command line
authorMark Wong <mark@2ndQuadrant.com>
Mon, 24 Jul 2017 01:45:06 +0000 (18:45 -0700)
committerMark Wong <mark@2ndQuadrant.com>
Tue, 19 Dec 2017 00:21:46 +0000 (16:21 -0800)
This allows testing of older versions of postgres.  Otherwise only
versions of postgres supporting ALTER SYSTEM (9.4+) will work with this
client.

client/utils/cluster.py

index b81eaef6039fad13a63129eccfc5ad28b314f4e5..d16d91dce6f7d16cd1ed77ccac39b6a3182414d1 100644 (file)
@@ -15,6 +15,8 @@ class PgCluster(object):
         self._bin = bin_path
         self._data = data_path
 
+        self._options = ""
+
     def _initdb(self):
         'initialize the data directory'
 
@@ -24,13 +26,10 @@ class PgCluster(object):
                  stdout=strout, stderr=STDOUT)
 
     def _configure(self, config):
-        'update configuration of a cluster (using postgresql.auto.conf)'
+        'build options list to use with pg_ctl'
 
-        log("configuring cluster in '%s'" % (self._data,))
-        with open('%s/postgresql.auto.conf' % (self._data,), 'a+') as f:
-            for k in config:
-                f.write("%(name)s = '%(value)s'\n" %
-                        {'name': k, 'value': config[k]})
+        for k in config:
+            self._options += ''.join([" -c ", k, "='", str(config[k]), "'"])
 
     def _destroy(self):
         """
@@ -59,8 +58,11 @@ class PgCluster(object):
         with TemporaryFile() as strout:
             log("starting cluster in '%s' using '%s' binaries" %
                 (self._data, self._bin))
-            call(['pg_ctl', '-D', self._data, '-l', 'pg.log', '-w', 'start'],
-                 env={'PATH': self._bin}, stdout=strout, stderr=STDOUT)
+            cmd = ['pg_ctl', '-D', self._data, '-l', 'pg.log', '-w']
+            if len(self._options) > 0:
+                cmd.extend(['-o', self._options])
+            cmd.append('start')
+            call(cmd, env={'PATH': self._bin}, stdout=strout, stderr=STDOUT)
 
     def stop(self, destroy=True):
         'stop the cluster'