37
37
*
38
38
*
39
39
* IDENTIFICATION
40
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.365 2004/02/08 22:28:56 neilc Exp $
40
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.366 2004/02/11 22:25:02 tgl Exp $
41
41
*
42
42
* NOTES
43
43
*
@@ -1079,7 +1079,8 @@ ServerLoop(void)
1079
1079
timeout .tv_usec = 0 ;
1080
1080
1081
1081
if (CheckPointPID == 0 && checkpointed &&
1082
- Shutdown == NoShutdown && !FatalError && random_seed != 0 )
1082
+ StartupPID == 0 && Shutdown == NoShutdown &&
1083
+ !FatalError && random_seed != 0 )
1083
1084
{
1084
1085
time_t now = time (NULL );
1085
1086
@@ -1113,7 +1114,8 @@ ServerLoop(void)
1113
1114
* this fails, we'll just try again later.
1114
1115
*/
1115
1116
if (BgWriterPID == 0 && BgWriterPercent > 0 &&
1116
- Shutdown == NoShutdown && !FatalError && random_seed != 0 )
1117
+ StartupPID == 0 && Shutdown == NoShutdown &&
1118
+ !FatalError && random_seed != 0 )
1117
1119
{
1118
1120
BgWriterPID = StartBackgroundWriter ();
1119
1121
}
@@ -1772,13 +1774,16 @@ pmdie(SIGNAL_ARGS)
1772
1774
*
1773
1775
* Wait for children to end their work and ShutdownDataBase.
1774
1776
*/
1775
- if (BgWriterPID != 0 )
1776
- kill (BgWriterPID ,SIGTERM );
1777
1777
if (Shutdown >=SmartShutdown )
1778
1778
break ;
1779
1779
Shutdown = SmartShutdown ;
1780
1780
ereport (LOG ,
1781
1781
(errmsg ("received smart shutdown request" )));
1782
+
1783
+ /* Must tell bgwriter to quit, or it never will... */
1784
+ if (BgWriterPID != 0 )
1785
+ kill (BgWriterPID ,SIGTERM );
1786
+
1782
1787
if (DLGetHead (BackendList ))/* let reaper() handle this */
1783
1788
break ;
1784
1789
@@ -1803,47 +1808,39 @@ pmdie(SIGNAL_ARGS)
1803
1808
/*
1804
1809
* Fast Shutdown:
1805
1810
*
1806
- *abort all children with SIGTERM (rollback active transactions
1811
+ *Abort all children with SIGTERM (rollback active transactions
1807
1812
* and exit) and ShutdownDataBase when they are gone.
1808
1813
*/
1809
- if (BgWriterPID != 0 )
1810
- kill (BgWriterPID ,SIGTERM );
1811
1814
if (Shutdown >=FastShutdown )
1812
1815
break ;
1816
+ Shutdown = FastShutdown ;
1813
1817
ereport (LOG ,
1814
1818
(errmsg ("received fast shutdown request" )));
1815
- if (DLGetHead (BackendList ))/* let reaper() handle this */
1819
+
1820
+ if (DLGetHead (BackendList ))
1816
1821
{
1817
- Shutdown = FastShutdown ;
1818
1822
if (!FatalError )
1819
1823
{
1820
1824
ereport (LOG ,
1821
1825
(errmsg ("aborting any active transactions" )));
1822
1826
SignalChildren (SIGTERM );
1827
+ /* reaper() does the rest */
1823
1828
}
1824
1829
break ;
1825
1830
}
1826
- if (Shutdown > NoShutdown )
1827
- {
1828
- Shutdown = FastShutdown ;
1829
- break ;
1830
- }
1831
- Shutdown = FastShutdown ;
1832
1831
1833
1832
/*
1834
1833
* No children left. Shutdown data base system.
1834
+ *
1835
+ * Unlike the previous case, it is not an error for the shutdown
1836
+ * process to be running already (we could get SIGTERM followed
1837
+ * shortly later by SIGINT).
1835
1838
*/
1836
1839
if (StartupPID > 0 || FatalError )/* let reaper() handle
1837
1840
* this */
1838
1841
break ;
1839
- if (ShutdownPID > 0 )
1840
- {
1841
- elog (PANIC ,"shutdown process %d already running" ,
1842
- (int )ShutdownPID );
1843
- abort ();
1844
- }
1845
-
1846
- ShutdownPID = ShutdownDataBase ();
1842
+ if (ShutdownPID == 0 )
1843
+ ShutdownPID = ShutdownDataBase ();
1847
1844
break ;
1848
1845
1849
1846
case SIGQUIT :
@@ -1854,8 +1851,6 @@ pmdie(SIGNAL_ARGS)
1854
1851
* abort all children with SIGQUIT and exit without attempt to
1855
1852
* properly shutdown data base system.
1856
1853
*/
1857
- if (BgWriterPID != 0 )
1858
- kill (BgWriterPID ,SIGQUIT );
1859
1854
ereport (LOG ,
1860
1855
(errmsg ("received immediate shutdown request" )));
1861
1856
if (ShutdownPID > 0 )
@@ -1973,12 +1968,6 @@ reaper(SIGNAL_ARGS)
1973
1968
CheckPointPID = 0 ;
1974
1969
checkpointed = time (NULL );
1975
1970
1976
- if (BgWriterPID == 0 && BgWriterPercent > 0 &&
1977
- Shutdown == NoShutdown && !FatalError && random_seed != 0 )
1978
- {
1979
- BgWriterPID = StartBackgroundWriter ();
1980
- }
1981
-
1982
1971
/*
1983
1972
* Go to shutdown mode if a shutdown request was pending.
1984
1973
*/
@@ -2101,8 +2090,8 @@ CleanupProc(int pid,
2101
2090
if (!FatalError )
2102
2091
{
2103
2092
LogChildExit (LOG ,
2104
- (pid == CheckPointPID ) ?gettext ("checkpoint process" ) :
2105
- (pid == BgWriterPID ) ?gettext ("bgwriter process" ) :
2093
+ (pid == CheckPointPID ) ?gettext ("checkpoint process" ) :
2094
+ (pid == BgWriterPID ) ?gettext ("bgwriter process" ) :
2106
2095
gettext ("server process" ),
2107
2096
pid ,exitstatus );
2108
2097
ereport (LOG ,
@@ -2844,7 +2833,8 @@ sigusr1_handler(SIGNAL_ARGS)
2844
2833
* is currently disabled
2845
2834
*/
2846
2835
if (CheckPointPID == 0 && checkpointed &&
2847
- Shutdown == NoShutdown && !FatalError && random_seed != 0 )
2836
+ StartupPID == 0 && Shutdown == NoShutdown &&
2837
+ !FatalError && random_seed != 0 )
2848
2838
{
2849
2839
CheckPointPID = CheckPointDataBase ();
2850
2840
/* note: if fork fails, CheckPointPID stays 0; nothing happens */
@@ -2975,6 +2965,7 @@ CountChildren(void)
2975
2965
if (bp -> pid != MyProcPid )
2976
2966
cnt ++ ;
2977
2967
}
2968
+ /* Checkpoint and bgwriter will be in the list, discount them */
2978
2969
if (CheckPointPID != 0 )
2979
2970
cnt -- ;
2980
2971
if (BgWriterPID != 0 )
@@ -2983,10 +2974,10 @@ CountChildren(void)
2983
2974
}
2984
2975
2985
2976
/*
2986
- * Fire off a subprocess for startup/shutdown/checkpoint.
2977
+ * Fire off a subprocess for startup/shutdown/checkpoint/bgwriter .
2987
2978
*
2988
2979
* Return value of SSDataBase is subprocess' PID, or 0 if failed to start subprocess
2989
- * (0 is returned only for checkpoint case ).
2980
+ * (0 is returned only for checkpoint/bgwriter cases ).
2990
2981
*
2991
2982
* note: in the EXEC_BACKEND case, we delay the fork until argument list has been
2992
2983
*established