mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
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.
This commit is contained in:
@@ -81,6 +81,12 @@
|
||||
#recovery_target_inclusive = true
|
||||
#
|
||||
#
|
||||
# Alternatively, you can request stopping as soon as a consistent state
|
||||
# is reached, by uncommenting this option.
|
||||
#
|
||||
#recovery_target = 'immediate'
|
||||
#
|
||||
#
|
||||
# If you want to recover into a timeline other than the "main line" shown in
|
||||
# pg_control, specify the timeline number here, or write 'latest' to get
|
||||
# the latest branch for which there's a history file.
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user