diff --git a/patroni/postgresql.py b/patroni/postgresql.py index e55bafbf..088416ab 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -44,6 +44,7 @@ class Postgresql(object): def __init__(self, config): self.config = config self.name = config['name'] + self.database = config.get('database', 'postgres') self._server_parameters = self.get_server_parameters(config) self._listen_addresses, self._port = (config['listen'] + ':5432').split(':')[:2] @@ -73,8 +74,8 @@ class Postgresql(object): self.local_address = self.get_local_address() connect_address = config.get('connect_address') or self.local_address - self.connection_string = 'postgres://{username}:{password}@{connect_address}/postgres'.format( - connect_address=connect_address, **self.replication) + self.connection_string = 'postgres://{username}:{password}@{connect_address}/{database}'.format( + connect_address=connect_address, database=self.database, **self.replication) self._connection = None self._cursor_holder = None @@ -144,7 +145,7 @@ class Postgresql(object): @property def _connect_kwargs(self): - r = parseurl('postgres://{0}/postgres'.format(self.local_address)) + r = parseurl('postgres://{0}/{1}'.format(self.local_address, self.database)) if 'username' in self.superuser: r['user'] = self.superuser['username'] if 'password' in self.superuser: @@ -504,8 +505,9 @@ class Postgresql(object): r = parseurl(leader.conn_url) r.update(self.pg_rewind) r['user'] = r.pop('username') + r['database'] = self.database env = self.write_pgpass(r) - pc = "user={user} host={host} port={port} dbname=postgres sslmode=prefer sslcompression=1".format(**r) + pc = "user={user} host={host} port={port} dbname={database} sslmode=prefer sslcompression=1".format(**r) # first run a checkpoint on a promoted master in order # to make it store the new timeline (5540277D.8020309@iki.fi) self.checkpoint(r) @@ -535,7 +537,7 @@ class Postgresql(object): for opt, val in sorted((options or {}).items()): cmd.extend(['-c', '{0}={1}'.format(opt, val)]) # need a database name to connect - cmd.append('postgres') + cmd.append(self.database) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) if p: if command: