aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2024-10-24 14:38:06 +0300
committerAlexander Korotkov <akorotkov@postgresql.org>2024-10-24 14:38:06 +0300
commit6cfebfe88b9a753152862b83d42d1103125b01bd (patch)
treef6fc4778defd31c965014d6ffe54f9ffba122163
parent5035172e4ab58e4e8eef1bc60b0712fc59e0be31 (diff)
downloadpostgresql-6cfebfe88b9a753152862b83d42d1103125b01bd.tar.gz
postgresql-6cfebfe88b9a753152862b83d42d1103125b01bd.zip
Make WaitForLSNReplay() issue FATAL on postmaster death
Reported-by: Michael Paquier Discussion: https://postgr.es/m/ZvY2C8N4ZqgCFaLu%40paquier.xyz Reviewed-by: Pavel Borisov
-rw-r--r--src/backend/access/transam/xlogwait.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index eef58ce69ce..353b7854dc8 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -222,7 +222,7 @@ WaitForLSNReplay(XLogRecPtr targetLSN, int64 timeout)
{
XLogRecPtr currentLSN;
TimestampTz endtime = 0;
- int wake_events = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH;
+ int wake_events = WL_LATCH_SET | WL_POSTMASTER_DEATH;
/* Shouldn't be called when shmem isn't initialized */
Assert(waitLSNState);
@@ -313,6 +313,16 @@ WaitForLSNReplay(XLogRecPtr targetLSN, int64 timeout)
rc = WaitLatch(MyLatch, wake_events, delay_ms,
WAIT_EVENT_WAIT_FOR_WAL_REPLAY);
+ /*
+ * Emergency bailout if postmaster has died. This is to avoid the
+ * necessity for manual cleanup of all postmaster children.
+ */
+ if (rc & WL_POSTMASTER_DEATH)
+ ereport(FATAL,
+ (errcode(ERRCODE_ADMIN_SHUTDOWN),
+ errmsg("terminating connection due to unexpected postmaster exit"),
+ errcontext("while waiting for LSN replay")));
+
if (rc & WL_LATCH_SET)
ResetLatch(MyLatch);
}