pgsql: Fix postmaster failing to exit when startup crashes during crash

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix postmaster failing to exit when startup crashes during crash
Date: 2026-08-20 06:17:57
Message-ID: E1www68-00000001K4L-1JEI@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix postmaster failing to exit when startup crashes during crash restart

Commit 9b43e6793b0f removed the PM_STARTUP shortcut that exited the
postmaster directly when the startup process died, routing the case
through HandleChildCrash() so that children processes running during
PM_STARTUP are cleaned up rather than orphaned.

However, HandleChildCrash() does nothing if FatalError is already set,
and that is exactly the case while reinitializing after a crash: a
relaunched startup process that dies before WAL redo starts would leave
the state machine stuck at PM_STARTUP, preventing the postmaster to shut
down.

This issue is fixed by restoring the pre-9b43e6793b0f shortcut behavior:
if FatalError is set when the startup process crashes, signal the
remaining children and move to PM_NO_CHILDREN, so as the postmaster can
properly exit with nothing orphaned. This is only reachable in v18 and
newer versions, the early return of HandleChildCrash() on FatalError
being introduced in f0b7ab725139.

This issue has been reported on Windows, for a postmaster with its
console gone. A trick to make InitPostmasterChild() fail aggressively
was equally able to stuck a postmaster.

Reported-by: Kuan-Ting Kuo <m0935388420(at)gmail(dot)com>
Author: Zexin Li <lizi(dot)openmind(at)gmail(dot)com>
Discussion: https://postgr.es/m/19623-f9bd331940be1273@postgresql.org
Backpatch-through: 18

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3861984342d85898a674fa0c7c93019317bfcff7

Modified Files
--------------
src/backend/postmaster/postmaster.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-08-20 07:08:40 pgsql: Unify error messages
Previous Message Amit Langote 2026-08-20 05:04:06 pgsql: Restore after-trigger firing context at subtransaction end