diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 45b17f5..353c259 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -66,7 +66,6 @@ extern uint32 bootstrap_data_checksum_version; #define RECOVERY_COMMAND_FILE "recovery.conf" #define RECOVERY_COMMAND_DONE "recovery.done" #define PROMOTE_SIGNAL_FILE "promote" -#define FAST_PROMOTE_SIGNAL_FILE "fast_promote" /* User-settable parameters */ @@ -225,9 +224,6 @@ static char *TriggerFile = NULL; /* are we currently in standby mode? */ bool StandbyMode = false; -/* whether request for fast promotion has been made yet */ -static bool fast_promote = false; - /* if recoveryStopsHere returns true, it saves actual stop xid/time/name here */ static TransactionId recoveryStopXid; static TimestampTz recoveryStopTime; @@ -4866,7 +4862,7 @@ StartupXLOG(void) DBState dbstate_at_startup; XLogReaderState *xlogreader; XLogPageReadPrivate private; - bool fast_promoted = false; + bool checkpoint_skip = false; /* * Read control file and check XLOG status looks valid. @@ -5962,43 +5958,40 @@ StartupXLOG(void) * the rule that TLI only changes in shutdown checkpoints, which * allows some extra error checking in xlog_redo. * - * In fast promotion, only create a lightweight end-of-recovery record + * In promotion, only create a lightweight end-of-recovery record * instead of a full checkpoint. A checkpoint is requested later, * after we're fully out of recovery mode and already accepting * queries. */ if (bgwriterLaunched) { - if (fast_promote) + checkPointLoc = ControlFile->prevCheckPoint; + + /* + * Confirm the last checkpoint is available for us to recover + * from if we fail. Note that we don't check for the secondary + * checkpoint since that isn't available in most base backups. + */ + record = ReadCheckpointRecord(xlogreader, checkPointLoc, 1, false); + if (record != NULL) { - checkPointLoc = ControlFile->prevCheckPoint; + checkpoint_skip = true; /* - * Confirm the last checkpoint is available for us to recover - * from if we fail. Note that we don't check for the secondary - * checkpoint since that isn't available in most base backups. + * Insert a special WAL record to mark the end of + * recovery, since we aren't doing a checkpoint. That + * means that the checkpointer process may likely be in + * the middle of a time-smoothed restartpoint and could + * continue to be for minutes after this. That sounds + * strange, but the effect is roughly the same and it + * would be stranger to try to come out of the + * restartpoint and then checkpoint. We request a + * checkpoint later anyway, just for safety. */ - record = ReadCheckpointRecord(xlogreader, checkPointLoc, 1, false); - if (record != NULL) - { - fast_promoted = true; - - /* - * Insert a special WAL record to mark the end of - * recovery, since we aren't doing a checkpoint. That - * means that the checkpointer process may likely be in - * the middle of a time-smoothed restartpoint and could - * continue to be for minutes after this. That sounds - * strange, but the effect is roughly the same and it - * would be stranger to try to come out of the - * restartpoint and then checkpoint. We request a - * checkpoint later anyway, just for safety. - */ - CreateEndOfRecoveryRecord(); - } + CreateEndOfRecoveryRecord(); } - if (!fast_promoted) + if (!checkpoint_skip) RequestCheckpoint(CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT); @@ -6111,12 +6104,12 @@ StartupXLOG(void) WalSndWakeup(); /* - * If this was a fast promotion, request an (online) checkpoint now. This + * If checkpoint_skip is true, request an (online) checkpoint now. This * isn't required for consistency, but the last restartpoint might be far * back, and in case of a crash, recovering from it might take a longer * than is appropriate now that we're not in standby mode anymore. */ - if (fast_promoted) + if (checkpoint_skip) RequestCheckpoint(CHECKPOINT_FORCE); } @@ -9931,16 +9924,11 @@ CheckForStandbyTrigger(void) * process do the unlink. This allows Startup to know whether we're * doing fast or normal promotion. Fast promotion takes precedence. */ - if (stat(FAST_PROMOTE_SIGNAL_FILE, &stat_buf) == 0) - { - unlink(FAST_PROMOTE_SIGNAL_FILE); - unlink(PROMOTE_SIGNAL_FILE); - fast_promote = true; - } - else if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0) + if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0) { + if (TriggerFile != NULL) + unlink(PROMOTE_SIGNAL_FILE); unlink(PROMOTE_SIGNAL_FILE); - fast_promote = false; } ereport(LOG, (errmsg("received promote request"))); @@ -9957,9 +9945,9 @@ CheckForStandbyTrigger(void) { ereport(LOG, (errmsg("trigger file found: %s", TriggerFile))); + unlink(PROMOTE_SIGNAL_FILE); unlink(TriggerFile); triggered = true; - fast_promote = true; return true; } return false; @@ -9974,8 +9962,7 @@ CheckPromoteSignal(void) { struct stat stat_buf; - if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0 || - stat(FAST_PROMOTE_SIGNAL_FILE, &stat_buf) == 0) + if (stat(PROMOTE_SIGNAL_FILE, &stat_buf) == 0) return true; return false; diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 9045e00..9e2b6c2 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -1099,12 +1099,10 @@ do_promote(void) } /* - * For 9.3 onwards, use fast promotion as the default option. Promotion - * with a full checkpoint is still possible by writing a file called - * "promote", e.g. snprintf(promote_file, MAXPGPATH, "%s/promote", - * pg_data); + * For 9.3 onwards, use fast promotion as the default option. + * This means a lightweight CheckPoint is executed when promoting. */ - snprintf(promote_file, MAXPGPATH, "%s/fast_promote", pg_data); + snprintf(promote_file, MAXPGPATH, "%s/promote", pg_data); if ((prmfile = fopen(promote_file, "w")) == NULL) {