Skip to content

Commit 946647f

Browse files
committed
Make pg_promote() detect postmaster death while waiting for promotion to end.
Previously even if postmaster died and WaitLatch() woke up with that event while pg_promote() was waiting for the standby promotion to finish, pg_promote() did nothing special and kept waiting until timeout occurred. This could cause a busy loop. This patch make pg_promote() return false immediately when postmaster dies, to avoid such a busy loop. Back-patch to v12 where pg_promote() was added. Author: Fujii Masao Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/CAHGQGwEs9ROgSp+QF+YdDU+xP8W=CY1k-_Ov-d_Z3JY+to3eXA@mail.gmail.com
1 parent fc8cb94 commit 946647f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/backend/access/transam/xlogfuncs.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,17 +759,26 @@ pg_promote(PG_FUNCTION_ARGS)
759759
#define WAITS_PER_SECOND 10
760760
for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
761761
{
762+
int rc;
763+
762764
ResetLatch(MyLatch);
763765

764766
if (!RecoveryInProgress())
765767
PG_RETURN_BOOL(true);
766768

767769
CHECK_FOR_INTERRUPTS();
768770

769-
(void) WaitLatch(MyLatch,
770-
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
771-
1000L / WAITS_PER_SECOND,
772-
WAIT_EVENT_PROMOTE);
771+
rc = WaitLatch(MyLatch,
772+
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
773+
1000L / WAITS_PER_SECOND,
774+
WAIT_EVENT_PROMOTE);
775+
776+
/*
777+
* Emergency bailout if postmaster has died. This is to avoid the
778+
* necessity for manual cleanup of all postmaster children.
779+
*/
780+
if (rc & WL_POSTMASTER_DEATH)
781+
PG_RETURN_BOOL(false);
773782
}
774783

775784
ereport(WARNING,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy