From cf34fb393430e78cbec375a72fc42809de76f1b4 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Tue, 15 Jan 2019 11:15:35 +0100 Subject: [PATCH] Relax requirements on superuser credentials (#930) libpq allows opening connection without explicitly specifying neither username nor password. Depending on situation it would rely either on `pgpass` file or trust authentication method in pg_hba.conf. Since pg_rewind is also using libpq, it could work the same way. Fixes https://github.com/zalando/patroni/issues/928 --- patroni/postgresql.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 46d04559..546b9982 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -392,7 +392,7 @@ class Postgresql(object): we have either wal_log_hints or checksums turned on """ # low-hanging fruit: check if pg_rewind configuration is there - if not (self.config.get('use_pg_rewind') and all(self._superuser.get(n) for n in ('username', 'password'))): + if not self.config.get('use_pg_rewind'): return False cmd = [self._pgcommand('pg_rewind'), '--help'] @@ -1673,7 +1673,8 @@ $$""".format(name, ' '.join(options)), name, password, password) def post_bootstrap(self, config, task): try: - self.create_or_update_role(self._superuser['username'], self._superuser['password'], ['SUPERUSER']) + if 'username' in self._superuser and 'password' in self._superuser: + self.create_or_update_role(self._superuser['username'], self._superuser['password'], ['SUPERUSER']) task.complete(self.run_bootstrap_post_init(config)) if task.result: