|
37 | 37 | *
|
38 | 38 | *
|
39 | 39 | * IDENTIFICATION
|
40 |
| - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.554 2008/03/31 02:43:14 tgl Exp $ |
| 40 | + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.555 2008/04/23 13:44:59 mha Exp $ |
41 | 41 | *
|
42 | 42 | * NOTES
|
43 | 43 | *
|
@@ -253,6 +253,7 @@ typedef enum
|
253 | 253 | PM_INIT, /* postmaster starting */
|
254 | 254 | PM_STARTUP, /* waiting for startup subprocess */
|
255 | 255 | PM_RUN, /* normal "database is alive" state */
|
| 256 | + PM_WAIT_BACKUP, /* waiting for online backup mode to end */ |
256 | 257 | PM_WAIT_BACKENDS, /* waiting for live backends to exit */
|
257 | 258 | PM_SHUTDOWN, /* waiting for bgwriter to do shutdown ckpt */
|
258 | 259 | PM_SHUTDOWN_2, /* waiting for archiver to finish */
|
@@ -1724,8 +1725,12 @@ processCancelRequest(Port *port, void *pkt)
|
1724 | 1725 | static enum CAC_state
|
1725 | 1726 | canAcceptConnections(void)
|
1726 | 1727 | {
|
1727 |
| - /* Can't start backends when in startup/shutdown/recovery state. */ |
1728 |
| - if (pmState != PM_RUN) |
| 1728 | + /* |
| 1729 | + * Can't start backends when in startup/shutdown/recovery state. |
| 1730 | + * In state PM_WAIT_BACKUP we must allow connections so that |
| 1731 | + * a superuser can end online backup mode. |
| 1732 | + */ |
| 1733 | + if ((pmState != PM_RUN) && (pmState != PM_WAIT_BACKUP)) |
1729 | 1734 | {
|
1730 | 1735 | if (Shutdown > NoShutdown)
|
1731 | 1736 | return CAC_SHUTDOWN; /* shutdown is pending */
|
@@ -1965,11 +1970,12 @@ pmdie(SIGNAL_ARGS)
|
1965 | 1970 | /* and the walwriter too */
|
1966 | 1971 | if (WalWriterPID != 0)
|
1967 | 1972 | signal_child(WalWriterPID, SIGTERM);
|
1968 |
| - pmState = PM_WAIT_BACKENDS; |
| 1973 | + pmState = PM_WAIT_BACKUP; |
1969 | 1974 | }
|
1970 | 1975 |
|
1971 | 1976 | /*
|
1972 |
| - * Now wait for backends to exit. If there are none, |
| 1977 | + * Now wait for online backup mode to end and |
| 1978 | + * backends to exit. If that is already the case, |
1973 | 1979 | * PostmasterStateMachine will take the next step.
|
1974 | 1980 | */
|
1975 | 1981 | PostmasterStateMachine();
|
@@ -2011,6 +2017,13 @@ pmdie(SIGNAL_ARGS)
|
2011 | 2017 | * PostmasterStateMachine will take the next step.
|
2012 | 2018 | */
|
2013 | 2019 | PostmasterStateMachine();
|
| 2020 | + |
| 2021 | + /* |
| 2022 | + * Terminate backup mode to avoid recovery after a |
| 2023 | + * clean fast shutdown. |
| 2024 | + */ |
| 2025 | + CancelBackup(); |
| 2026 | + |
2014 | 2027 | break;
|
2015 | 2028 |
|
2016 | 2029 | case SIGQUIT:
|
@@ -2552,6 +2565,20 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
|
2552 | 2565 | static void
|
2553 | 2566 | PostmasterStateMachine(void)
|
2554 | 2567 | {
|
| 2568 | + if (pmState == PM_WAIT_BACKUP) |
| 2569 | + { |
| 2570 | + /* |
| 2571 | + * PM_WAIT_BACKUP state ends when online backup mode is no longer |
| 2572 | + * active. In this state canAcceptConnections() will still allow |
| 2573 | + * client connections, which is necessary because a superuser |
| 2574 | + * has to call pg_stop_backup() to end online backup mode. |
| 2575 | + */ |
| 2576 | + if (!BackupInProgress()) |
| 2577 | + { |
| 2578 | + pmState = PM_WAIT_BACKENDS; |
| 2579 | + } |
| 2580 | + } |
| 2581 | + |
2555 | 2582 | /*
|
2556 | 2583 | * If we are in a state-machine state that implies waiting for backends to
|
2557 | 2584 | * exit, see if they're all gone, and change state if so.
|
|
0 commit comments