*** pgsql/src/backend/postmaster/postmaster.c 2008/03/31 02:43:14 1.554 --- pgsql/src/backend/postmaster/postmaster.c 2008/04/23 13:44:59 1.555 *************** *** 37,43 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.553 2008/03/09 04:56:28 tgl Exp $ * * NOTES * --- 37,43 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.554 2008/03/31 02:43:14 tgl Exp $ * * NOTES * *************** typedef enum *** 253,258 **** --- 253,259 ---- PM_INIT, /* postmaster starting */ PM_STARTUP, /* waiting for startup subprocess */ PM_RUN, /* normal "database is alive" state */ + PM_WAIT_BACKUP, /* waiting for online backup mode to end */ PM_WAIT_BACKENDS, /* waiting for live backends to exit */ PM_SHUTDOWN, /* waiting for bgwriter to do shutdown ckpt */ PM_SHUTDOWN_2, /* waiting for archiver to finish */ *************** processCancelRequest(Port *port, void *p *** 1724,1731 **** static enum CAC_state canAcceptConnections(void) { ! /* Can't start backends when in startup/shutdown/recovery state. */ ! if (pmState != PM_RUN) { if (Shutdown > NoShutdown) return CAC_SHUTDOWN; /* shutdown is pending */ --- 1725,1736 ---- static enum CAC_state canAcceptConnections(void) { ! /* ! * Can't start backends when in startup/shutdown/recovery state. ! * In state PM_WAIT_BACKUP we must allow connections so that ! * a superuser can end online backup mode. ! */ ! if ((pmState != PM_RUN) && (pmState != PM_WAIT_BACKUP)) { if (Shutdown > NoShutdown) return CAC_SHUTDOWN; /* shutdown is pending */ *************** pmdie(SIGNAL_ARGS) *** 1965,1975 **** /* and the walwriter too */ if (WalWriterPID != 0) signal_child(WalWriterPID, SIGTERM); ! pmState = PM_WAIT_BACKENDS; } /* ! * Now wait for backends to exit. If there are none, * PostmasterStateMachine will take the next step. */ PostmasterStateMachine(); --- 1970,1981 ---- /* and the walwriter too */ if (WalWriterPID != 0) signal_child(WalWriterPID, SIGTERM); ! pmState = PM_WAIT_BACKUP; } /* ! * Now wait for online backup mode to end and ! * backends to exit. If that is already the case, * PostmasterStateMachine will take the next step. */ PostmasterStateMachine(); *************** pmdie(SIGNAL_ARGS) *** 2011,2016 **** --- 2017,2029 ---- * PostmasterStateMachine will take the next step. */ PostmasterStateMachine(); + + /* + * Terminate backup mode to avoid recovery after a + * clean fast shutdown. + */ + CancelBackup(); + break; case SIGQUIT: *************** LogChildExit(int lev, const char *procna *** 2552,2557 **** --- 2565,2584 ---- static void PostmasterStateMachine(void) { + if (pmState == PM_WAIT_BACKUP) + { + /* + * PM_WAIT_BACKUP state ends when online backup mode is no longer + * active. In this state canAcceptConnections() will still allow + * client connections, which is necessary because a superuser + * has to call pg_stop_backup() to end online backup mode. + */ + if (!BackupInProgress()) + { + pmState = PM_WAIT_BACKENDS; + } + } + /* * If we are in a state-machine state that implies waiting for backends to * exit, see if they're all gone, and change state if so.