diff options
author | Magnus Hagander <magnus@hagander.net> | 2008-04-23 13:44:59 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2008-04-23 13:44:59 +0000 |
commit | c979a1fefafcc83553bf218c7f2270cad77ea31d (patch) | |
tree | 7bbf70239a28d7bd5bf239fd93ebc1f37a85c39e /src/backend/postmaster/postmaster.c | |
parent | cf23b75b4dce75151df7164ed72263e66b758ae9 (diff) | |
download | postgresql-c979a1fefafcc83553bf218c7f2270cad77ea31d.tar.gz postgresql-c979a1fefafcc83553bf218c7f2270cad77ea31d.zip |
Prevent shutdown in normal mode if online backup is running, and
have pg_ctl warn about this.
Cancel running online backups (by renaming the backup_label file,
thus rendering the backup useless) when shutting down in fast mode.
Laurenz Albe
Diffstat (limited to 'src/backend/postmaster/postmaster.c')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 7c6692b2a5d..f3bcdd968c7 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.554 2008/03/31 02:43:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.555 2008/04/23 13:44:59 mha Exp $ * * NOTES * @@ -253,6 +253,7 @@ typedef enum 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 */ @@ -1724,8 +1725,12 @@ processCancelRequest(Port *port, void *pkt) static enum CAC_state canAcceptConnections(void) { - /* Can't start backends when in startup/shutdown/recovery state. */ - if (pmState != PM_RUN) + /* + * 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 */ @@ -1965,11 +1970,12 @@ pmdie(SIGNAL_ARGS) /* and the walwriter too */ if (WalWriterPID != 0) signal_child(WalWriterPID, SIGTERM); - pmState = PM_WAIT_BACKENDS; + pmState = PM_WAIT_BACKUP; } /* - * Now wait for backends to exit. If there are none, + * 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(); @@ -2011,6 +2017,13 @@ pmdie(SIGNAL_ARGS) * PostmasterStateMachine will take the next step. */ PostmasterStateMachine(); + + /* + * Terminate backup mode to avoid recovery after a + * clean fast shutdown. + */ + CancelBackup(); + break; case SIGQUIT: @@ -2552,6 +2565,20 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus) 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. |