Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b5fe620

Browse files
committed
Make postmaster restart archiver soon after it dies, even during recovery.
After the archiver dies, postmaster tries to start a new one immediately. But previously this could happen only while server was running normally even though archiving was enabled always (i.e., archive_mode was set to always). So the archiver running during recovery could not restart soon after it died. This is an oversight in commit ffd3774. This commit changes reaper(), postmaster's signal handler to cleanup after a child process dies, so that it tries to a new archiver even during recovery if necessary. Patch by me. Review by Alvaro Herrera.
1 parent 96ad72d commit b5fe620

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ static pid_t StartChildProcess(AuxProcType type);
406406
static void StartAutovacuumWorker(void);
407407
static void InitPostmasterDeathWatchHandle(void);
408408

409+
/*
410+
* Archiver is allowed to start up at the current postmaster state?
411+
*
412+
* If WAL archiving is enabled always, we are allowed to start archiver
413+
* even during recovery.
414+
*/
415+
#define PgArchStartupAllowed() \
416+
((XLogArchivingActive() && pmState == PM_RUN) || \
417+
(XLogArchivingAlways() && \
418+
(pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY)))
419+
409420
#ifdef EXEC_BACKEND
410421

411422
#ifdef WIN32
@@ -1649,21 +1660,9 @@ ServerLoop(void)
16491660
if (PgStatPID == 0 && pmState == PM_RUN)
16501661
PgStatPID = pgstat_start();
16511662

1652-
/*
1653-
* If we have lost the archiver, try to start a new one.
1654-
*
1655-
* If WAL archiving is enabled always, we try to start a new archiver
1656-
* even during recovery.
1657-
*/
1658-
if (PgArchPID == 0 && wal_level >= WAL_LEVEL_ARCHIVE)
1659-
{
1660-
if ((pmState == PM_RUN && XLogArchiveMode > ARCHIVE_MODE_OFF) ||
1661-
((pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY) &&
1662-
XLogArchiveMode == ARCHIVE_MODE_ALWAYS))
1663-
{
1663+
/* If we have lost the archiver, try to start a new one. */
1664+
if (PgArchPID == 0 && PgArchStartupAllowed())
16641665
PgArchPID = pgarch_start();
1665-
}
1666-
}
16671666

16681667
/* If we need to signal the autovacuum launcher, do so now */
16691668
if (avlauncher_needs_signal)
@@ -2669,7 +2668,7 @@ reaper(SIGNAL_ARGS)
26692668
*/
26702669
if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0)
26712670
AutoVacPID = StartAutoVacLauncher();
2672-
if (XLogArchivingActive() && PgArchPID == 0)
2671+
if (PgArchStartupAllowed() && PgArchPID == 0)
26732672
PgArchPID = pgarch_start();
26742673
if (PgStatPID == 0)
26752674
PgStatPID = pgstat_start();
@@ -2810,7 +2809,7 @@ reaper(SIGNAL_ARGS)
28102809
if (!EXIT_STATUS_0(exitstatus))
28112810
LogChildExit(LOG, _("archiver process"),
28122811
pid, exitstatus);
2813-
if (XLogArchivingActive() && pmState == PM_RUN)
2812+
if (PgArchStartupAllowed())
28142813
PgArchPID = pgarch_start();
28152814
continue;
28162815
}
@@ -4833,11 +4832,8 @@ sigusr1_handler(SIGNAL_ARGS)
48334832
* files.
48344833
*/
48354834
Assert(PgArchPID == 0);
4836-
if (wal_level >= WAL_LEVEL_ARCHIVE &&
4837-
XLogArchiveMode == ARCHIVE_MODE_ALWAYS)
4838-
{
4835+
if (XLogArchivingAlways())
48394836
PgArchPID = pgarch_start();
4840-
}
48414837

48424838
pmState = PM_RECOVERY;
48434839
}

src/include/access/xlog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ typedef enum WalLevel
126126
} WalLevel;
127127
extern int wal_level;
128128

129+
/* Is WAL archiving enabled (always or only while server is running normally)? */
129130
#define XLogArchivingActive() \
130131
(XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level >= WAL_LEVEL_ARCHIVE)
132+
/* Is WAL archiving enabled always (even during recovery)? */
133+
#define XLogArchivingAlways() \
134+
(XLogArchiveMode == ARCHIVE_MODE_ALWAYS && wal_level >= WAL_LEVEL_ARCHIVE)
131135
#define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
132136

133137
/*

0 commit comments

Comments
 (0)