Ignore hba_file and ident_file when they match with defaults (#1555)

It is possible to specify custom hba_file and ident_file in the postgresql configuration parameters and Patroni is considering that these files are managed externally. It could happen that locations of these files matching with default locations of pg_hba,conf and pg_ident.conf. In this case we will ignore custom values and fallback to the default workflow, i.e. Patroni will overwrite them.

Close: https://github.com/zalando/patroni/issues/1544
This commit is contained in:
Alexander Kukushkin
2020-06-05 09:33:50 +02:00
committed by GitHub
parent 1b2491cedf
commit 1229cf2c16
2 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -363,7 +363,7 @@ END;$$""".format(f, rewind['username'])
# at this point there should be no recovery.conf
postgresql.config.remove_recovery_conf()
if postgresql.config.hba_file and postgresql.config.hba_file != postgresql.config.pg_hba_conf:
if postgresql.config.hba_file:
postgresql.restart()
else:
postgresql.config.replace_pg_hba()
+13 -5
View File
@@ -376,7 +376,7 @@ class ConfigHandler(object):
configuration.append(os.path.basename(self._postgresql_base_conf_name))
if not self.hba_file:
configuration.append('pg_hba.conf')
if not self._server_parameters.get('ident_file'):
if not self.ident_file:
configuration.append('pg_ident.conf')
return configuration
@@ -483,7 +483,7 @@ class ConfigHandler(object):
:returns: True if pg_ident.conf was rewritten.
"""
if not self._server_parameters.get('ident_file') and self._config.get('pg_ident'):
if not self.ident_file and self._config.get('pg_ident'):
with ConfigWriter(self._pg_ident_conf) as f:
f.writelines(self._config['pg_ident'])
return True
@@ -963,10 +963,12 @@ class ConfigHandler(object):
logger.warning('Removing invalid parameter `%s` from postgresql.parameters', param)
server_parameters.pop(param)
if not server_parameters.get('hba_file') and config.get('pg_hba'):
if (not server_parameters.get('hba_file') or server_parameters['hba_file'] == self._pg_hba_conf) \
and config.get('pg_hba'):
hba_changed = self._config.get('pg_hba', []) != config['pg_hba']
if not server_parameters.get('ident_file') and config.get('pg_ident'):
if (not server_parameters.get('ident_file') or server_parameters['ident_file'] == self._pg_hba_conf) \
and config.get('pg_ident'):
ident_changed = self._config.get('pg_ident', []) != config['pg_ident']
self._config = config
@@ -1073,9 +1075,15 @@ class ConfigHandler(object):
return self._config['authentication'].get('rewind', self._superuser) \
if self._postgresql.major_version >= 110000 else self._superuser
@property
def ident_file(self):
ident_file = self._server_parameters.get('ident_file')
return None if ident_file == self._pg_ident_conf else ident_file
@property
def hba_file(self):
return self._server_parameters.get('hba_file')
hba_file = self._server_parameters.get('hba_file')
return None if hba_file == self._pg_hba_conf else hba_file
@property
def pg_hba_conf(self):