From edf372e8b697e30dbf32346d133d23efd7bddbda Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Mon, 9 May 2016 09:41:06 +0200 Subject: [PATCH] Reset _sysid and don't call pg_controldata when restore of backup in progress Otherwise there were some errors in a log from rest-api healthcheck endpoint --- patroni/postgresql.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index e771bcfb..4178d572 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -261,6 +261,8 @@ class Postgresql(object): for replica_method in replica_methods) def create_replica(self, clone_member, env): + self.set_state('creating replica') + self._sysid = None # create the replica according to the replica_method # defined by the user. this is a list, so we need to # loop through all methods the user supplies @@ -308,6 +310,7 @@ class Postgresql(object): logger.exception('Error creating replica using method {0}: {1}'.format(replica_method, str(e))) ret = 1 + self.set_state('stopped') return ret def is_leader(self): @@ -501,13 +504,14 @@ class Postgresql(object): def controldata(self): """ return the contents of pg_controldata, or non-True value if pg_controldata call failed """ result = {} - try: - data = subprocess.check_output(['pg_controldata', self.data_dir]) - if data: - data = data.decode('utf-8').splitlines() - result = {l.split(':')[0].replace('Current ', '', 1): l.split(':')[1].strip() for l in data if l} - except subprocess.CalledProcessError: - logger.exception("Error when calling pg_controldata") + if self.state != 'creating replica': # Don't try to call pg_controldata during backup restore + try: + data = subprocess.check_output(['pg_controldata', self.data_dir]) + if data: + data = data.decode('utf-8').splitlines() + result = {l.split(':')[0].replace('Current ', '', 1): l.split(':')[1].strip() for l in data if l} + except subprocess.CalledProcessError: + logger.exception("Error when calling pg_controldata") return result def read_postmaster_opts(self):