From 728a521c1d79256e0e1dcf2511c7860fc57f8856 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Thu, 27 Apr 2017 14:35:01 +0200 Subject: [PATCH] Export locale variables when forking a postmaster. (#437) Avoid "postmaster became multithreaded during startup" error on OS X built with --enable-nls (default for petere/homebrew). The issue is that on OS X the libintl that replaces setlocale() spawns a thread when it needs to detect the current locale. Setting the LC_ and LANG variables prevents this, but we don't propagate them to the fork. See: https://www.postgresql.org/message-id/flat/20140902013458.GB906981%40tornado.leadboat.com#20140902013458.GB906981@tornado.leadboat.com for an additional explanation of the original Postgres behavior. --- patroni/postgresql.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 1f05c91c..9f279138 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -720,7 +720,8 @@ class Postgresql(object): # In order to make everything portable we can't use fork&exec approach here, so we will call # ourselves and pass list of arguments which must be used to start postgres. proc = call_self(['pg_ctl_start', self._pgcommand('postgres'), '-D', self._data_dir] + options, close_fds=True, - preexec_fn=os.setsid, stdout=subprocess.PIPE, env={'PATH': os.environ.get('PATH')}) + preexec_fn=os.setsid, stdout=subprocess.PIPE, + env={p: os.environ[p] for p in ('PATH', 'LC_ALL', 'LANG') if p in os.environ}) pid = int(proc.stdout.readline().strip()) proc.wait() logger.info('postmaster pid=%s', pid)