diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-01-25 17:34:04 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-01-25 17:34:04 +0200 |
commit | 71c6a8e375b138af8aa46d80226ea9e98f2b94bc (patch) | |
tree | b81980fab354a0b9abfd7e9b1b39b6c3eb6d05b4 /src/backend/access/transam/xlog.c | |
parent | 820f08cabdcbb8998050c3d4873e9619d6d8cba4 (diff) | |
download | postgresql-71c6a8e375b138af8aa46d80226ea9e98f2b94bc.tar.gz postgresql-71c6a8e375b138af8aa46d80226ea9e98f2b94bc.zip |
Add recovery_target='immediate' option.
This allows ending recovery as a consistent state has been reached. Without
this, there was no easy way to e.g restore an online backup, without
replaying any extra WAL after the backup ended.
MauMau and me.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 9559d6d6aef..b333d820c72 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5434,6 +5434,19 @@ readRecoveryCommandFile(void) (errmsg_internal("recovery_target_name = '%s'", recoveryTargetName))); } + else if (strcmp(item->name, "recovery_target") == 0) + { + if (strcmp(item->value, "immediate") == 0) + recoveryTarget = RECOVERY_TARGET_IMMEDIATE; + else + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid recovery_target parameter"), + errhint("The only allowed value is 'immediate'"))); + ereport(DEBUG2, + (errmsg_internal("recovery_target = '%s'", + item->value))); + } else if (strcmp(item->name, "recovery_target_inclusive") == 0) { /* @@ -5676,7 +5689,20 @@ recoveryStopsBefore(XLogRecord *record) bool isCommit; TimestampTz recordXtime = 0; - /* We only consider stopping before COMMIT or ABORT records. */ + /* Check if we should stop as soon as reaching consistency */ + if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE && reachedConsistency) + { + ereport(LOG, + (errmsg("recovery stopping after reaching consistency"))); + + recoveryStopAfter = false; + recoveryStopXid = InvalidTransactionId; + recoveryStopTime = 0; + recoveryStopName[0] = '\0'; + return true; + } + + /* Otherwise we only consider stopping before COMMIT or ABORT records. */ if (record->xl_rmid != RM_XACT_ID) return false; record_info = record->xl_info & ~XLR_INFO_MASK; @@ -5825,6 +5851,19 @@ recoveryStopsAfter(XLogRecord *record) } } + /* Check if we should stop as soon as reaching consistency */ + if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE && reachedConsistency) + { + ereport(LOG, + (errmsg("recovery stopping after reaching consistency"))); + + recoveryStopAfter = true; + recoveryStopXid = InvalidTransactionId; + recoveryStopTime = 0; + recoveryStopName[0] = '\0'; + return true; + } + return false; } @@ -6246,6 +6285,9 @@ StartupXLOG(void) ereport(LOG, (errmsg("starting point-in-time recovery to \"%s\"", recoveryTargetName))); + else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE) + ereport(LOG, + (errmsg("starting point-in-time recovery to earliest consistent point"))); else ereport(LOG, (errmsg("starting archive recovery"))); @@ -7125,6 +7167,8 @@ StartupXLOG(void) snprintf(reason, sizeof(reason), "at restore point \"%s\"", recoveryStopName); + else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE) + snprintf(reason, sizeof(reason), "reached consistency"); else snprintf(reason, sizeof(reason), "no recovery target specified"); |