postgres.git / summary / log / commit / refs

commit    504bd2e8daf03ccb959e9cbe44f5ca1afd8feb77
Author:   Fujii Masao <fujii@postgresql.org>
Date:     Wed Nov 18 04:28:48 2026 +0000

    Fix handling of backend crashes during standby promotion
    
    If a backend crashed as a standby finishes promotion, the server could
    resume normal operation without resetting shared memory and performing
    crash recovery. With restart_after_crash disabled, it could keep running
    instead of shutting down as required.
    
    This happened when the postmaster detected the backend crash and sent
    SIGQUIT to the startup process, but that process had already exited or
    was too far along in its normal exit sequence to respond to the signal.
    The postmaster then treated its zero exit status as successful startup,
    clearing FatalError and entering PM_RUN despite the backend crash.
    
    Fix this by honoring STARTUP_SIGNALED even when the startup process
    exits with status zero. This lets the postmaster finish handling
    the crash and either restart or shut down, according to restart_after_crash.
    
    A failure of 041_checkpoint_at_promote.pl on buildfarm member tamandua
    exposed this race in the server's handling of backend crashes. Although
    the test was introduced in v17, the bug affects all supported versions.
    
    Backpatch to all supported versions.
    
    Reported-by: Alexander Lakhin <exclusion@gmail.com>
    Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
    Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
    Discussion: https://postgr.es/m/1c733765-62af-48b3-b0d7-1e744c8b8522@gmail.com
    Backpatch-through: 15


src/backend/postmaster/postmaster.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index f399667e84a..6480e058cf0 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -2289,12 +2289,13 @@ process_pm_child_exit(void) * during PM_STARTUP due to some dead-end child crashing: in that * situation, if the startup process dies on the SIGQUIT, we need * to transition to PM_WAIT_BACKENDS state which will allow - * PostmasterStateMachine to restart the startup process. (On the - * other hand, the startup process might complete normally, if we - * were too late with the SIGQUIT. In that case we'll fall - * through and commence normal operations.) + * PostmasterStateMachine to restart the startup process. + * + * SIGQUIT may arrive too late to change the startup process's + * exit status. If we signaled it, continue the crash restart + * even if it exits normally. */ - if (!EXIT_STATUS_0(exitstatus)) + if (!EXIT_STATUS_0(exitstatus) || StartupStatus == STARTUP_SIGNALED) { if (StartupStatus == STARTUP_SIGNALED) { [parent: 65efcf45768c]