*** a/src/backend/libpq/be-secure.c --- b/src/backend/libpq/be-secure.c *************** *** 36,42 **** #include "tcop/tcopprot.h" #include "utils/memutils.h" #include "storage/proc.h" ! char *ssl_cert_file; char *ssl_key_file; --- 36,42 ---- #include "tcop/tcopprot.h" #include "utils/memutils.h" #include "storage/proc.h" ! #include "storage/ipc.h" char *ssl_cert_file; char *ssl_key_file; *************** *** 144,151 **** retry: Assert(waitfor); w = WaitLatchOrSocket(MyLatch, ! WL_LATCH_SET | waitfor, port->sock, 0); /* Handle interrupt. */ if (w & WL_LATCH_SET) --- 144,158 ---- Assert(waitfor); w = WaitLatchOrSocket(MyLatch, ! WL_LATCH_SET | WL_POSTMASTER_DEATH | waitfor, port->sock, 0); + /* + * Emergency bailout if postmaster has died. This is to avoid the + * necessity for manual cleanup of all postmaster children. + */ + if (w & WL_POSTMASTER_DEATH) + proc_exit(1); + /* Handle interrupt. */ if (w & WL_LATCH_SET) *************** *** 223,230 **** retry: Assert(waitfor); w = WaitLatchOrSocket(MyLatch, ! WL_LATCH_SET | waitfor, port->sock, 0); /* Handle interrupt. */ if (w & WL_LATCH_SET) --- 230,243 ---- Assert(waitfor); w = WaitLatchOrSocket(MyLatch, ! WL_LATCH_SET | WL_POSTMASTER_DEATH | waitfor, port->sock, 0); + /* + * Emergency bailout if postmaster has died. This is to avoid the + * necessity for manual cleanup of all postmaster children. + */ + if (w & WL_POSTMASTER_DEATH) + proc_exit(1); /* Handle interrupt. */ if (w & WL_LATCH_SET) *** a/src/backend/tcop/postgres.c --- b/src/backend/tcop/postgres.c *************** *** 74,79 **** --- 74,80 ---- #include "utils/timeout.h" #include "utils/timestamp.h" #include "mb/pg_wchar.h" + #include "storage/pmsignal.h" /* ---------------- *************** *** 3985,3990 **** PostgresMain(int argc, char *argv[], --- 3986,4001 ---- firstchar = ReadCommand(&input_message); /* + * Emergency bailout if postmaster has died. This is to avoid the + * necessity for manual cleanup of all postmaster children. + * Note: In most cases it will be caught inside ReadCommand but incase + * it is able to read command without waiting on latch, this is the + * place to catch postmaster death scenario. + */ + if (IsUnderPostmaster && !PostmasterIsAlive()) + proc_exit(1); + + /* * (4) disable async signal conditions again. * * Query cancel is supposed to be a no-op when there is no query in