From fd4f12aac8ae9523dad3304167ca4b9a9c50db61 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 21 Apr 2016 13:56:09 +0200 Subject: [PATCH] Do not assume that connection user is postgres, but take it from config.yml --- features/environment.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/environment.py b/features/environment.py index 851b458c..ebda756e 100644 --- a/features/environment.py +++ b/features/environment.py @@ -115,7 +115,9 @@ class PatroniController(AbstractController): config['postgresql']['listen'] = config['postgresql']['connect_address'] = '{0}:{1}'.format(host, self.__PORT) - self._connstring = 'host={0} port={1} dbname=postgres user=postgres'.format(host, self.__PORT) + user = config['postgresql'].get('superuser', {}) + self._connkwargs = {k: user[n] for n, k in [('username', 'user'), ('password', 'password')] if n in user} + self._connkwargs.update({'host': host, 'port': self.__PORT, 'database': 'postgres'}) config['postgresql'].update({'name': name, 'data_dir': self._data_dir}) config['postgresql']['parameters'].update({ @@ -141,7 +143,7 @@ class PatroniController(AbstractController): def _connection(self): if not self._conn or self._conn.closed != 0: - self._conn = psycopg2.connect(self._connstring) + self._conn = psycopg2.connect(**self._connkwargs) self._conn.autocommit = True return self._conn