Skip to content

Commit a1f680d

Browse files
committed
Allow replication slots to be dropped in single-user mode
Starting with commit 9915de6, replication slot drop uses a condition variable sleep to wait until the current user of the slot goes away. This is more user friendly than the previous behavior of erroring out if the slot is in use, but it fails with a not-for-user-consumption error message in single-user mode; plus, if you're using single-user mode because you don't want to start the server in the regular mode (say, disk is full and WAL won't recycle because of the slot), it's inconvenient. Fix by skipping the cond variable sleep in single-user mode, since there can't be anybody to wait for anyway. Reported-by: tushar <tushar.ahuja@enterprisedb.com> Author: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/3b2f809f-326c-38dd-7a9e-897f957a4eb1@enterprisedb.com
1 parent bba8c61 commit a1f680d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/backend/replication/slot.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,28 @@ ReplicationSlotAcquire(const char *name, bool nowait)
351351
if (s->in_use && strcmp(name, NameStr(s->data.name)) == 0)
352352
{
353353
/*
354-
* This is the slot we want. We don't know yet if it's active, so
355-
* get ready to sleep on it in case it is. (We may end up not
356-
* sleeping, but we don't want to do this while holding the
357-
* spinlock.)
354+
* This is the slot we want; check if it's active under some other
355+
* process. In single user mode, we don't need this check.
358356
*/
359-
ConditionVariablePrepareToSleep(&s->active_cv);
357+
if (IsUnderPostmaster)
358+
{
359+
/*
360+
* Get ready to sleep on it in case it is active. (We may end
361+
* up not sleeping, but we don't want to do this while holding
362+
* the spinlock.)
363+
*/
364+
ConditionVariablePrepareToSleep(&s->active_cv);
360365

361-
SpinLockAcquire(&s->mutex);
366+
SpinLockAcquire(&s->mutex);
362367

363-
active_pid = s->active_pid;
364-
if (active_pid == 0)
365-
active_pid = s->active_pid = MyProcPid;
368+
active_pid = s->active_pid;
369+
if (active_pid == 0)
370+
active_pid = s->active_pid = MyProcPid;
366371

367-
SpinLockRelease(&s->mutex);
372+
SpinLockRelease(&s->mutex);
373+
}
374+
else
375+
active_pid = MyProcPid;
368376
slot = s;
369377

370378
break;

0 commit comments

Comments
 (0)