From 59eb9253797776f21267d35b608582b5fd3ff67c Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 8 May 2018 11:48:56 -0300 Subject: [PATCH 1/2] don't try cond variables if single user mode --- src/backend/replication/slot.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index a8a16f55e9..a43f402214 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -351,20 +351,28 @@ retry: if (s->in_use && strcmp(name, NameStr(s->data.name)) == 0) { /* - * This is the slot we want. We don't know yet if it's active, so - * get ready to sleep on it in case it is. (We may end up not - * sleeping, but we don't want to do this while holding the - * spinlock.) + * This is the slot we want; check if it's active under some other + * process. In single user mode, we don't need this check. */ - ConditionVariablePrepareToSleep(&s->active_cv); + if (IsUnderPostmaster) + { + /* + * Get ready to sleep on it in case it is active. (We may end + * up not sleeping, but we don't want to do this while holding + * the spinlock.) + */ + ConditionVariablePrepareToSleep(&s->active_cv); - SpinLockAcquire(&s->mutex); + SpinLockAcquire(&s->mutex); - active_pid = s->active_pid; - if (active_pid == 0) - active_pid = s->active_pid = MyProcPid; + active_pid = s->active_pid; + if (active_pid == 0) + active_pid = s->active_pid = MyProcPid; - SpinLockRelease(&s->mutex); + SpinLockRelease(&s->mutex); + } + else + active_pid = MyProcPid; slot = s; break; -- 2.11.0