* PM_WAIT_BACKENDS state ends when we have no regular backends
* (including autovac workers), no bgworkers (including unconnected
* ones), and no walwriter, autovac launcher or bgwriter. If we are
- * doing crash recovery then we expect the checkpointer to exit as
- * well, otherwise not. The archiver, stats, and syslogger processes
- * are disregarded since they are not connected to shared memory; we
- * also disregard dead_end children here. Walsenders are also
- * disregarded, they will be terminated later after writing the
- * checkpoint record, like the archiver process.
+ * doing crash recovery or an immediate shutdown then we expect
+ * the checkpointer to exit as well, otherwise not. The archiver,
+ * stats, and syslogger processes are disregarded since
+ * they are not connected to shared memory; we also disregard
+ * dead_end children here. Walsenders are also disregarded,
+ * they will be terminated later after writing the checkpoint record,
+ * like the archiver process.
*/
if (CountChildren(BACKEND_TYPE_NORMAL | BACKEND_TYPE_WORKER) == 0 &&
CountUnconnectedWorkers() == 0 &&
StartupPID == 0 &&
WalReceiverPID == 0 &&
BgWriterPID == 0 &&
- (CheckpointerPID == 0 || !FatalError) &&
+ (CheckpointerPID == 0 ||
+ (!FatalError && Shutdown < ImmediateShutdown)) &&
WalWriterPID == 0 &&
AutoVacPID == 0)
{