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.
This commit is contained in:
parent
96ad72d1c0
commit
b5fe62038f
@ -406,6 +406,17 @@ static pid_t StartChildProcess(AuxProcType type);
|
|||||||
static void StartAutovacuumWorker(void);
|
static void StartAutovacuumWorker(void);
|
||||||
static void InitPostmasterDeathWatchHandle(void);
|
static void InitPostmasterDeathWatchHandle(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Archiver is allowed to start up at the current postmaster state?
|
||||||
|
*
|
||||||
|
* If WAL archiving is enabled always, we are allowed to start archiver
|
||||||
|
* even during recovery.
|
||||||
|
*/
|
||||||
|
#define PgArchStartupAllowed() \
|
||||||
|
((XLogArchivingActive() && pmState == PM_RUN) || \
|
||||||
|
(XLogArchivingAlways() && \
|
||||||
|
(pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY)))
|
||||||
|
|
||||||
#ifdef EXEC_BACKEND
|
#ifdef EXEC_BACKEND
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -1649,21 +1660,9 @@ ServerLoop(void)
|
|||||||
if (PgStatPID == 0 && pmState == PM_RUN)
|
if (PgStatPID == 0 && pmState == PM_RUN)
|
||||||
PgStatPID = pgstat_start();
|
PgStatPID = pgstat_start();
|
||||||
|
|
||||||
/*
|
/* If we have lost the archiver, try to start a new one. */
|
||||||
* If we have lost the archiver, try to start a new one.
|
if (PgArchPID == 0 && PgArchStartupAllowed())
|
||||||
*
|
|
||||||
* If WAL archiving is enabled always, we try to start a new archiver
|
|
||||||
* even during recovery.
|
|
||||||
*/
|
|
||||||
if (PgArchPID == 0 && wal_level >= WAL_LEVEL_ARCHIVE)
|
|
||||||
{
|
|
||||||
if ((pmState == PM_RUN && XLogArchiveMode > ARCHIVE_MODE_OFF) ||
|
|
||||||
((pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY) &&
|
|
||||||
XLogArchiveMode == ARCHIVE_MODE_ALWAYS))
|
|
||||||
{
|
|
||||||
PgArchPID = pgarch_start();
|
PgArchPID = pgarch_start();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we need to signal the autovacuum launcher, do so now */
|
/* If we need to signal the autovacuum launcher, do so now */
|
||||||
if (avlauncher_needs_signal)
|
if (avlauncher_needs_signal)
|
||||||
@ -2669,7 +2668,7 @@ reaper(SIGNAL_ARGS)
|
|||||||
*/
|
*/
|
||||||
if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0)
|
if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0)
|
||||||
AutoVacPID = StartAutoVacLauncher();
|
AutoVacPID = StartAutoVacLauncher();
|
||||||
if (XLogArchivingActive() && PgArchPID == 0)
|
if (PgArchStartupAllowed() && PgArchPID == 0)
|
||||||
PgArchPID = pgarch_start();
|
PgArchPID = pgarch_start();
|
||||||
if (PgStatPID == 0)
|
if (PgStatPID == 0)
|
||||||
PgStatPID = pgstat_start();
|
PgStatPID = pgstat_start();
|
||||||
@ -2810,7 +2809,7 @@ reaper(SIGNAL_ARGS)
|
|||||||
if (!EXIT_STATUS_0(exitstatus))
|
if (!EXIT_STATUS_0(exitstatus))
|
||||||
LogChildExit(LOG, _("archiver process"),
|
LogChildExit(LOG, _("archiver process"),
|
||||||
pid, exitstatus);
|
pid, exitstatus);
|
||||||
if (XLogArchivingActive() && pmState == PM_RUN)
|
if (PgArchStartupAllowed())
|
||||||
PgArchPID = pgarch_start();
|
PgArchPID = pgarch_start();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -4833,11 +4832,8 @@ sigusr1_handler(SIGNAL_ARGS)
|
|||||||
* files.
|
* files.
|
||||||
*/
|
*/
|
||||||
Assert(PgArchPID == 0);
|
Assert(PgArchPID == 0);
|
||||||
if (wal_level >= WAL_LEVEL_ARCHIVE &&
|
if (XLogArchivingAlways())
|
||||||
XLogArchiveMode == ARCHIVE_MODE_ALWAYS)
|
|
||||||
{
|
|
||||||
PgArchPID = pgarch_start();
|
PgArchPID = pgarch_start();
|
||||||
}
|
|
||||||
|
|
||||||
pmState = PM_RECOVERY;
|
pmState = PM_RECOVERY;
|
||||||
}
|
}
|
||||||
|
@ -126,8 +126,12 @@ typedef enum WalLevel
|
|||||||
} WalLevel;
|
} WalLevel;
|
||||||
extern int wal_level;
|
extern int wal_level;
|
||||||
|
|
||||||
|
/* Is WAL archiving enabled (always or only while server is running normally)? */
|
||||||
#define XLogArchivingActive() \
|
#define XLogArchivingActive() \
|
||||||
(XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level >= WAL_LEVEL_ARCHIVE)
|
(XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level >= WAL_LEVEL_ARCHIVE)
|
||||||
|
/* Is WAL archiving enabled always (even during recovery)? */
|
||||||
|
#define XLogArchivingAlways() \
|
||||||
|
(XLogArchiveMode == ARCHIVE_MODE_ALWAYS && wal_level >= WAL_LEVEL_ARCHIVE)
|
||||||
#define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
|
#define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user