*** a/src/backend/postmaster/postmaster.c --- b/src/backend/postmaster/postmaster.c *************** *** 224,229 **** static int Shutdown = NoShutdown; --- 224,231 ---- static bool FatalError = false; /* T if recovering from backend crash */ static bool RecoveryError = false; /* T if WAL recovery failed */ + static bool NeedBackupLabel = false; /* T if backup_label is still required */ + /* * We use a simple state machine to control startup, shutdown, and * crash recovery (which is rather like shutdown followed by startup). *************** *** 267,272 **** static bool RecoveryError = false; /* T if WAL recovery failed */ --- 269,278 ---- * because we don't clear it until we've successfully started WAL redo. * Similarly, RecoveryError means that we have crashed during recovery, and * should not try to restart. + * + * If shutdown is requested in PM_STARTUP state, the postmaster sets the + * NeedBackupLabel to true and skips renaming the backup_label file since + * it's still required for subsequent recovery. */ typedef enum { *************** *** 2167,2174 **** pmdie(SIGNAL_ARGS) ereport(LOG, (errmsg("received smart shutdown request"))); if (pmState == PM_RUN || pmState == PM_RECOVERY || ! pmState == PM_HOT_STANDBY) { /* autovacuum workers are told to shut down immediately */ SignalAutovacWorkers(SIGTERM); --- 2173,2182 ---- ereport(LOG, (errmsg("received smart shutdown request"))); + if (pmState == PM_STARTUP) + NeedBackupLabel = true; if (pmState == PM_RUN || pmState == PM_RECOVERY || ! pmState == PM_HOT_STANDBY || pmState == PM_STARTUP) { /* autovacuum workers are told to shut down immediately */ SignalAutovacWorkers(SIGTERM); *************** *** 2217,2222 **** pmdie(SIGNAL_ARGS) --- 2225,2232 ---- signal_child(StartupPID, SIGTERM); if (WalReceiverPID != 0) signal_child(WalReceiverPID, SIGTERM); + if (pmState == PM_STARTUP) + NeedBackupLabel = true; if (pmState == PM_RECOVERY) { /* only bgwriter is active in this state */ *************** *** 3030,3036 **** PostmasterStateMachine(void) * Terminate backup mode to avoid recovery after a clean fast * shutdown. */ ! CancelBackup(); /* Normal exit from the postmaster is here */ ExitPostmaster(0); --- 3040,3047 ---- * Terminate backup mode to avoid recovery after a clean fast * shutdown. */ ! if (!NeedBackupLabel) ! CancelBackup(); /* Normal exit from the postmaster is here */ ExitPostmaster(0);