37
37
*
38
38
*
39
39
* IDENTIFICATION
40
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.555 2008/04/23 13:44:59 mha Exp $
40
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.556 2008/04/26 22:47:40 tgl Exp $
41
41
*
42
42
* NOTES
43
43
*
@@ -230,6 +230,7 @@ static bool FatalError = false; /* T if recovering from backend crash */
230
230
* crash recovery (which is rather like shutdown followed by startup).
231
231
*
232
232
* Normal child backends can only be launched when we are in PM_RUN state.
233
+ * (We also allow it in PM_WAIT_BACKUP state, but only for superusers.)
233
234
* In other states we handle connection requests by launching "dead_end"
234
235
* child processes, which will simply send the client an error message and
235
236
* quit. (We track these in the BackendList so that we can know when they
@@ -242,9 +243,9 @@ static bool FatalError = false; /* T if recovering from backend crash */
242
243
* will not be very long).
243
244
*
244
245
* Notice that this state variable does not distinguish *why* we entered
245
- * PM_WAIT_BACKENDS or later states --- Shutdown and FatalError must be
246
- * consulted to find that out. FatalError is never true in PM_RUN state, nor
247
- * in PM_SHUTDOWN states (because we don't enter those states when trying to
246
+ * states later than PM_RUN --- Shutdown and FatalError must be consulted
247
+ * to find that out. FatalError is never true in PM_RUN state, nor in
248
+ * PM_SHUTDOWN states (because we don't enter those states when trying to
248
249
* recover from a crash). It can be true in PM_STARTUP state, because we
249
250
* don't clear it until we've successfully recovered.
250
251
*/
@@ -1650,6 +1651,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
1650
1651
(errcode (ERRCODE_TOO_MANY_CONNECTIONS ),
1651
1652
errmsg ("sorry, too many clients already" )));
1652
1653
break ;
1654
+ case CAC_WAITBACKUP :
1655
+ /* OK for now, will check in InitPostgres */
1656
+ break ;
1653
1657
case CAC_OK :
1654
1658
break ;
1655
1659
}
@@ -1727,11 +1731,15 @@ canAcceptConnections(void)
1727
1731
{
1728
1732
/*
1729
1733
* 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.
1734
+ *
1735
+ * In state PM_WAIT_BACKUP only superusers can connect (this must be
1736
+ * allowed so that a superuser can end online backup mode); we return
1737
+ * CAC_WAITBACKUP code to indicate that this must be checked later.
1732
1738
*/
1733
- if (( pmState != PM_RUN ) && ( pmState != PM_WAIT_BACKUP ) )
1739
+ if (pmState != PM_RUN )
1734
1740
{
1741
+ if (pmState == PM_WAIT_BACKUP )
1742
+ return CAC_WAITBACKUP ; /* allow superusers only */
1735
1743
if (Shutdown > NoShutdown )
1736
1744
return CAC_SHUTDOWN ; /* shutdown is pending */
1737
1745
if (pmState == PM_STARTUP && !FatalError )
@@ -1997,7 +2005,7 @@ pmdie(SIGNAL_ARGS)
1997
2005
1998
2006
if (StartupPID != 0 )
1999
2007
signal_child (StartupPID , SIGTERM );
2000
- if (pmState == PM_RUN )
2008
+ if (pmState == PM_RUN || pmState == PM_WAIT_BACKUP )
2001
2009
{
2002
2010
ereport (LOG ,
2003
2011
(errmsg ("aborting any active transactions" )));
@@ -2017,13 +2025,6 @@ pmdie(SIGNAL_ARGS)
2017
2025
* PostmasterStateMachine will take the next step.
2018
2026
*/
2019
2027
PostmasterStateMachine ();
2020
-
2021
- /*
2022
- * Terminate backup mode to avoid recovery after a
2023
- * clean fast shutdown.
2024
- */
2025
- CancelBackup ();
2026
-
2027
2028
break ;
2028
2029
2029
2030
case SIGQUIT :
@@ -2499,7 +2500,9 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
2499
2500
2500
2501
FatalError = true;
2501
2502
/* We now transit into a state of waiting for children to die */
2502
- if (pmState == PM_RUN || pmState == PM_SHUTDOWN )
2503
+ if (pmState == PM_RUN ||
2504
+ pmState == PM_WAIT_BACKUP ||
2505
+ pmState == PM_SHUTDOWN )
2503
2506
pmState = PM_WAIT_BACKENDS ;
2504
2507
}
2505
2508
@@ -2568,15 +2571,10 @@ PostmasterStateMachine(void)
2568
2571
if (pmState == PM_WAIT_BACKUP )
2569
2572
{
2570
2573
/*
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.
2574
+ * PM_WAIT_BACKUP state ends when online backup mode is not active.
2575
2575
*/
2576
2576
if (!BackupInProgress ())
2577
- {
2578
2577
pmState = PM_WAIT_BACKENDS ;
2579
- }
2580
2578
}
2581
2579
2582
2580
/*
@@ -2699,6 +2697,12 @@ PostmasterStateMachine(void)
2699
2697
}
2700
2698
else
2701
2699
{
2700
+ /*
2701
+ * Terminate backup mode to avoid recovery after a
2702
+ * clean fast shutdown.
2703
+ */
2704
+ CancelBackup ();
2705
+
2702
2706
/* Normal exit from the postmaster is here */
2703
2707
ExitPostmaster (0 );
2704
2708
}
@@ -2819,7 +2823,7 @@ BackendStartup(Port *port)
2819
2823
return STATUS_ERROR ;
2820
2824
}
2821
2825
2822
- /* Pass down canAcceptConnections state (kluge for EXEC_BACKEND case) */
2826
+ /* Pass down canAcceptConnections state */
2823
2827
port -> canAcceptConnections = canAcceptConnections ();
2824
2828
2825
2829
#ifdef EXEC_BACKEND
@@ -2880,7 +2884,8 @@ BackendStartup(Port *port)
2880
2884
bn -> pid = pid ;
2881
2885
bn -> cancel_key = MyCancelKey ;
2882
2886
bn -> is_autovacuum = false;
2883
- bn -> dead_end = (port -> canAcceptConnections != CAC_OK );
2887
+ bn -> dead_end = (port -> canAcceptConnections != CAC_OK &&
2888
+ port -> canAcceptConnections != CAC_WAITBACKUP );
2884
2889
DLAddHead (BackendList , DLNewElem (bn ));
2885
2890
#ifdef EXEC_BACKEND
2886
2891
if (!bn -> dead_end )
0 commit comments