From 01d0ccabc6b2b33c4a6f9b0ceb251a0eed23357f Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 4 Feb 2009 14:33:28 +0200 Subject: [PATCH] Fix FatalError handling. Bug pointed out by Fujii-san. --- src/backend/access/transam/xlog.c | 3 ++- src/backend/postmaster/postmaster.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index c01aa9f7fb..7143bf9dee 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6433,7 +6433,8 @@ CreateRestartPoint(int flags) * If the last checkpoint record we've replayed is already our last * restartpoint, we're done. */ - if (XLByteLE(lastCheckPoint.redo, ControlFile->checkPointCopy.redo)) + if (XLogRecPtrIsInvalid(lastCheckPointRecPtr) || + XLByteLE(lastCheckPoint.redo, ControlFile->checkPointCopy.redo)) { ereport(DEBUG2, (errmsg("skipping restartpoint, already performed at %X/%X", diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 15fc7ad3d6..12e74ab366 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -271,10 +271,10 @@ static int RecoveryStatus = NoRecovery; * * Notice that this state variable does not distinguish *why* we entered * states later than PM_RUN --- Shutdown and FatalError must be consulted - * to find that out. FatalError is never true in PM_RUN state, nor in - * PM_SHUTDOWN states (because we don't enter those states when trying to - * recover from a crash). It can be true in PM_STARTUP state, because we - * don't clear it until we've successfully recovered. + * to find that out. FatalError is never true in PM_RECOVERY_* or PM_RUN + * states, nor in PM_SHUTDOWN states (because we don't enter those states + * when trying to recover from a crash). It can be true in PM_STARTUP state, + * because we don't clear it until we've successfully started WAL redo. */ typedef enum { @@ -1783,7 +1783,10 @@ canAcceptConnections(void) return CAC_WAITBACKUP; /* allow superusers only */ if (Shutdown > NoShutdown) return CAC_SHUTDOWN; /* shutdown is pending */ - if (pmState == PM_STARTUP && !FatalError) + if (!FatalError && + (pmState == PM_STARTUP || + pmState == PM_RECOVERY || + pmState == PM_RECOVERY_CONSISTENT)) return CAC_STARTUP; /* normal startup */ return CAC_RECOVERY; /* else must be crash recovery */ } @@ -2617,7 +2620,8 @@ PostmasterStateMachine(void) if (pmState == PM_STARTUP && RecoveryStatus > NoRecovery) { - /* Recovery has started */ + /* WAL redo has started. We're out of reinitialization. */ + FatalError = false; /* * Go to shutdown mode if a shutdown request was pending. -- 2.39.5