|
37 | 37 | *
|
38 | 38 | *
|
39 | 39 | * IDENTIFICATION
|
40 |
| - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.604 2010/03/25 20:40:17 sriggs Exp $ |
| 40 | + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.605 2010/04/08 01:39:37 rhaas Exp $ |
41 | 41 | *
|
42 | 42 | * NOTES
|
43 | 43 | *
|
@@ -278,6 +278,7 @@ typedef enum
|
278 | 278 | PM_RECOVERY_CONSISTENT, /* consistent recovery mode */
|
279 | 279 | PM_RUN, /* normal "database is alive" state */
|
280 | 280 | PM_WAIT_BACKUP, /* waiting for online backup mode to end */
|
| 281 | + PM_WAIT_READONLY, /* waiting for read only backends to exit */ |
281 | 282 | PM_WAIT_BACKENDS, /* waiting for live backends to exit */
|
282 | 283 | PM_SHUTDOWN, /* waiting for bgwriter to do shutdown ckpt */
|
283 | 284 | PM_SHUTDOWN_2, /* waiting for archiver and walsenders to
|
@@ -2173,7 +2174,17 @@ pmdie(SIGNAL_ARGS)
|
2173 | 2174 | /* and the walwriter too */
|
2174 | 2175 | if (WalWriterPID != 0)
|
2175 | 2176 | signal_child(WalWriterPID, SIGTERM);
|
2176 |
| - pmState = PM_WAIT_BACKUP; |
| 2177 | + /* |
| 2178 | + * If we're in recovery, we can't kill the startup process |
| 2179 | + * right away, because at present doing so does not release |
| 2180 | + * its locks. We might want to change this in a future |
| 2181 | + * release. For the time being, the PM_WAIT_READONLY state |
| 2182 | + * indicates that we're waiting for the regular (read only) |
| 2183 | + * backends to die off; once they do, we'll kill the startup |
| 2184 | + * and walreceiver processes. |
| 2185 | + */ |
| 2186 | + pmState = (pmState == PM_RUN) ? |
| 2187 | + PM_WAIT_BACKUP : PM_WAIT_READONLY; |
2177 | 2188 | }
|
2178 | 2189 |
|
2179 | 2190 | /*
|
@@ -2209,6 +2220,7 @@ pmdie(SIGNAL_ARGS)
|
2209 | 2220 | }
|
2210 | 2221 | if (pmState == PM_RUN ||
|
2211 | 2222 | pmState == PM_WAIT_BACKUP ||
|
| 2223 | + pmState == PM_WAIT_READONLY || |
2212 | 2224 | pmState == PM_WAIT_BACKENDS ||
|
2213 | 2225 | pmState == PM_RECOVERY_CONSISTENT)
|
2214 | 2226 | {
|
@@ -2771,6 +2783,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
|
2771 | 2783 | pmState == PM_RECOVERY_CONSISTENT ||
|
2772 | 2784 | pmState == PM_RUN ||
|
2773 | 2785 | pmState == PM_WAIT_BACKUP ||
|
| 2786 | + pmState == PM_WAIT_READONLY || |
2774 | 2787 | pmState == PM_SHUTDOWN)
|
2775 | 2788 | pmState = PM_WAIT_BACKENDS;
|
2776 | 2789 | }
|
@@ -2846,6 +2859,26 @@ PostmasterStateMachine(void)
|
2846 | 2859 | pmState = PM_WAIT_BACKENDS;
|
2847 | 2860 | }
|
2848 | 2861 |
|
| 2862 | + if (pmState == PM_WAIT_READONLY) |
| 2863 | + { |
| 2864 | + /* |
| 2865 | + * PM_WAIT_READONLY state ends when we have no regular backends that |
| 2866 | + * have been started during recovery. We kill the startup and |
| 2867 | + * walreceiver processes and transition to PM_WAIT_BACKENDS. Ideally, |
| 2868 | + * we might like to kill these processes first and then wait for |
| 2869 | + * backends to die off, but that doesn't work at present because |
| 2870 | + * killing the startup process doesn't release its locks. |
| 2871 | + */ |
| 2872 | + if (CountChildren(BACKEND_TYPE_NORMAL) == 0) |
| 2873 | + { |
| 2874 | + if (StartupPID != 0) |
| 2875 | + signal_child(StartupPID, SIGTERM); |
| 2876 | + if (WalReceiverPID != 0) |
| 2877 | + signal_child(WalReceiverPID, SIGTERM); |
| 2878 | + pmState = PM_WAIT_BACKENDS; |
| 2879 | + } |
| 2880 | + } |
| 2881 | + |
2849 | 2882 | /*
|
2850 | 2883 | * If we are in a state-machine state that implies waiting for backends to
|
2851 | 2884 | * exit, see if they're all gone, and change state if so.
|
|
0 commit comments