From d47671e5b645544e1e407146e6f1b3f03bd042e8 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Tue, 31 May 2016 13:18:18 +0200 Subject: [PATCH] ALTER USER does not add LOGIN to the non-login role --- patroni/postgresql.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 22916086..452e2e6d 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -724,7 +724,11 @@ class Postgresql(object): self.call_nowait(ACTION_ON_ROLE_CHANGE) return ret - def create_or_update_user(self, name, password, options): + def create_or_update_role(self, name, password, options): + options = list(map(str.upper, options)) + if 'NOLOGIN' not in options and 'LOGIN' not in options: + options.append('LOGIN') + self.query("""DO $$ BEGIN SET local synchronous_commit = 'local'; @@ -735,7 +739,7 @@ BEGIN CREATE USER "{0}" WITH {1} PASSWORD %s; END IF; END; -$$""".format(name, options), name, password, password) +$$""".format(name, ' '.join(options)), name, password, password) def xlog_position(self): return self.query("""SELECT pg_xlog_location_diff(CASE WHEN pg_is_in_recovery() @@ -804,8 +808,8 @@ $$""".format(name, options), name, password, password) if self._initialize(config) and self.start(): for name, value in config['users'].items(): if name not in (self._superuser.get('username'), self._replication['username']): - self.create_or_update_user(name, value['password'], ' '.join(value.get('options', [])).upper()) - self.create_or_update_user(self._replication['username'], self._replication['password'], 'REPLICATION') + self.create_or_update_role(name, value['password'], value.get('options', [])) + self.create_or_update_role(self._replication['username'], self._replication['password'], ['REPLICATION']) else: raise PostgresException("Could not bootstrap master PostgreSQL")