aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2018-07-06 16:38:29 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2018-07-06 16:38:29 -0400
commita1f680d962ffdd563eee7665da5b3b9967a6070f (patch)
tree209893f95cc5f2f115c01962ac9c0a3e9d309174 /src
parentbba8c612117416907f332fce8b9e80b748e0b798 (diff)
downloadpostgresql-a1f680d962ffdd563eee7665da5b3b9967a6070f.tar.gz
postgresql-a1f680d962ffdd563eee7665da5b3b9967a6070f.zip
Allow replication slots to be dropped in single-user mode
Starting with commit 9915de6c1cb2, 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
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/slot.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index cf5baf686ee..bb9a24ec08d 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;