Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0cb117e

Browse files
committed
Repair some problems in bgwriter start/stop logic. In particular, don't
allow the bgwriter to start before the startup subprocess has finished... it tends to crash otherwise. (The same problem may have existed forthe checkpointer, I'm not entirely sure.) Remove some code that wasredundant because the bgwriter is handled as a member of the backend list.
1 parent3b6bf0c commit0cb117e

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* 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 $
4141
*
4242
* NOTES
4343
*
@@ -1079,7 +1079,8 @@ ServerLoop(void)
10791079
timeout.tv_usec=0;
10801080

10811081
if (CheckPointPID==0&&checkpointed&&
1082-
Shutdown==NoShutdown&& !FatalError&&random_seed!=0)
1082+
StartupPID==0&&Shutdown==NoShutdown&&
1083+
!FatalError&&random_seed!=0)
10831084
{
10841085
time_tnow=time(NULL);
10851086

@@ -1113,7 +1114,8 @@ ServerLoop(void)
11131114
* this fails, we'll just try again later.
11141115
*/
11151116
if (BgWriterPID==0&&BgWriterPercent>0&&
1116-
Shutdown==NoShutdown&& !FatalError&&random_seed!=0)
1117+
StartupPID==0&&Shutdown==NoShutdown&&
1118+
!FatalError&&random_seed!=0)
11171119
{
11181120
BgWriterPID=StartBackgroundWriter();
11191121
}
@@ -1772,13 +1774,16 @@ pmdie(SIGNAL_ARGS)
17721774
*
17731775
* Wait for children to end their work and ShutdownDataBase.
17741776
*/
1775-
if (BgWriterPID!=0)
1776-
kill(BgWriterPID,SIGTERM);
17771777
if (Shutdown >=SmartShutdown)
17781778
break;
17791779
Shutdown=SmartShutdown;
17801780
ereport(LOG,
17811781
(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+
17821787
if (DLGetHead(BackendList))/* let reaper() handle this */
17831788
break;
17841789

@@ -1803,47 +1808,39 @@ pmdie(SIGNAL_ARGS)
18031808
/*
18041809
* Fast Shutdown:
18051810
*
1806-
*abort all children with SIGTERM (rollback active transactions
1811+
*Abort all children with SIGTERM (rollback active transactions
18071812
* and exit) and ShutdownDataBase when they are gone.
18081813
*/
1809-
if (BgWriterPID!=0)
1810-
kill(BgWriterPID,SIGTERM);
18111814
if (Shutdown >=FastShutdown)
18121815
break;
1816+
Shutdown=FastShutdown;
18131817
ereport(LOG,
18141818
(errmsg("received fast shutdown request")));
1815-
if (DLGetHead(BackendList))/* let reaper() handle this */
1819+
1820+
if (DLGetHead(BackendList))
18161821
{
1817-
Shutdown=FastShutdown;
18181822
if (!FatalError)
18191823
{
18201824
ereport(LOG,
18211825
(errmsg("aborting any active transactions")));
18221826
SignalChildren(SIGTERM);
1827+
/* reaper() does the rest */
18231828
}
18241829
break;
18251830
}
1826-
if (Shutdown>NoShutdown)
1827-
{
1828-
Shutdown=FastShutdown;
1829-
break;
1830-
}
1831-
Shutdown=FastShutdown;
18321831

18331832
/*
18341833
* 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).
18351838
*/
18361839
if (StartupPID>0||FatalError)/* let reaper() handle
18371840
* this */
18381841
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();
18471844
break;
18481845

18491846
caseSIGQUIT:
@@ -1854,8 +1851,6 @@ pmdie(SIGNAL_ARGS)
18541851
* abort all children with SIGQUIT and exit without attempt to
18551852
* properly shutdown data base system.
18561853
*/
1857-
if (BgWriterPID!=0)
1858-
kill(BgWriterPID,SIGQUIT);
18591854
ereport(LOG,
18601855
(errmsg("received immediate shutdown request")));
18611856
if (ShutdownPID>0)
@@ -1973,12 +1968,6 @@ reaper(SIGNAL_ARGS)
19731968
CheckPointPID=0;
19741969
checkpointed=time(NULL);
19751970

1976-
if (BgWriterPID==0&&BgWriterPercent>0&&
1977-
Shutdown==NoShutdown&& !FatalError&&random_seed!=0)
1978-
{
1979-
BgWriterPID=StartBackgroundWriter();
1980-
}
1981-
19821971
/*
19831972
* Go to shutdown mode if a shutdown request was pending.
19841973
*/
@@ -2101,8 +2090,8 @@ CleanupProc(int pid,
21012090
if (!FatalError)
21022091
{
21032092
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") :
21062095
gettext("server process"),
21072096
pid,exitstatus);
21082097
ereport(LOG,
@@ -2844,7 +2833,8 @@ sigusr1_handler(SIGNAL_ARGS)
28442833
* is currently disabled
28452834
*/
28462835
if (CheckPointPID==0&&checkpointed&&
2847-
Shutdown==NoShutdown&& !FatalError&&random_seed!=0)
2836+
StartupPID==0&&Shutdown==NoShutdown&&
2837+
!FatalError&&random_seed!=0)
28482838
{
28492839
CheckPointPID=CheckPointDataBase();
28502840
/* note: if fork fails, CheckPointPID stays 0; nothing happens */
@@ -2975,6 +2965,7 @@ CountChildren(void)
29752965
if (bp->pid!=MyProcPid)
29762966
cnt++;
29772967
}
2968+
/* Checkpoint and bgwriter will be in the list, discount them */
29782969
if (CheckPointPID!=0)
29792970
cnt--;
29802971
if (BgWriterPID!=0)
@@ -2983,10 +2974,10 @@ CountChildren(void)
29832974
}
29842975

29852976
/*
2986-
* Fire off a subprocess for startup/shutdown/checkpoint.
2977+
* Fire off a subprocess for startup/shutdown/checkpoint/bgwriter.
29872978
*
29882979
* 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).
29902981
*
29912982
* note: in the EXEC_BACKEND case, we delay the fork until argument list has been
29922983
*established

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp