Commit 3cdafe40 authored by Simon Riggs's avatar Simon Riggs

Adjust comment in .history file to match recovery target specified. Comment

present since 8.0 was never fully meaningful, since two recovery targets
cannot be specified. Refactor recovery target type to make this change
and associated code easier to understand. No change in function.

Bug report arising from internal support question.
parent 5c73ae17
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.382 2010/03/18 09:17:18 heikki Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.383 2010/03/19 11:05:14 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -172,8 +172,7 @@ static bool restoredFromArchive = false; ...@@ -172,8 +172,7 @@ static bool restoredFromArchive = false;
static char *recoveryRestoreCommand = NULL; static char *recoveryRestoreCommand = NULL;
static char *recoveryEndCommand = NULL; static char *recoveryEndCommand = NULL;
static char *restartPointCommand = NULL; static char *restartPointCommand = NULL;
static bool recoveryTarget = false; static RecoveryTargetType recoveryTarget = RECOVERY_TARGET_UNSET;
static bool recoveryTargetExact = false;
static bool recoveryTargetInclusive = true; static bool recoveryTargetInclusive = true;
static TransactionId recoveryTargetXid; static TransactionId recoveryTargetXid;
static TimestampTz recoveryTargetTime; static TimestampTz recoveryTargetTime;
...@@ -4224,14 +4223,32 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, ...@@ -4224,14 +4223,32 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
*/ */
XLogFileName(xlogfname, endTLI, endLogId, endLogSeg); XLogFileName(xlogfname, endTLI, endLogId, endLogSeg);
snprintf(buffer, sizeof(buffer), /*
"%s%u\t%s\t%s transaction %u at %s\n", * Write comment to history file to explain why and where timeline changed.
(srcfd < 0) ? "" : "\n", * Comment varies according to the recovery target used.
parentTLI, */
xlogfname, if (recoveryTarget == RECOVERY_TARGET_XID)
recoveryStopAfter ? "after" : "before", snprintf(buffer, sizeof(buffer),
recoveryStopXid, "%s%u\t%s\t%s transaction %u\n",
timestamptz_to_str(recoveryStopTime)); (srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
recoveryStopXid);
if (recoveryTarget == RECOVERY_TARGET_TIME)
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\t%s %s\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
timestamptz_to_str(recoveryStopTime));
else
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\tno recovery target specified\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname);
nbytes = strlen(buffer); nbytes = strlen(buffer);
errno = 0; errno = 0;
...@@ -4978,8 +4995,7 @@ readRecoveryCommandFile(void) ...@@ -4978,8 +4995,7 @@ readRecoveryCommandFile(void)
ereport(DEBUG2, ereport(DEBUG2,
(errmsg("recovery_target_xid = %u", (errmsg("recovery_target_xid = %u",
recoveryTargetXid))); recoveryTargetXid)));
recoveryTarget = true; recoveryTarget = RECOVERY_TARGET_XID;
recoveryTargetExact = true;
} }
else if (strcmp(tok1, "recovery_target_time") == 0) else if (strcmp(tok1, "recovery_target_time") == 0)
{ {
...@@ -4987,10 +5003,9 @@ readRecoveryCommandFile(void) ...@@ -4987,10 +5003,9 @@ readRecoveryCommandFile(void)
* if recovery_target_xid specified, then this overrides * if recovery_target_xid specified, then this overrides
* recovery_target_time * recovery_target_time
*/ */
if (recoveryTargetExact) if (recoveryTarget == RECOVERY_TARGET_XID)
continue; continue;
recoveryTarget = true; recoveryTarget = RECOVERY_TARGET_TIME;
recoveryTargetExact = false;
/* /*
* Convert the time string given by the user to TimestampTz form. * Convert the time string given by the user to TimestampTz form.
...@@ -5265,13 +5280,13 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis) ...@@ -5265,13 +5280,13 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis)
return false; return false;
/* Do we have a PITR target at all? */ /* Do we have a PITR target at all? */
if (!recoveryTarget) if (recoveryTarget == RECOVERY_TARGET_UNSET)
{ {
recoveryLastXTime = recordXtime; recoveryLastXTime = recordXtime;
return false; return false;
} }
if (recoveryTargetExact) if (recoveryTarget == RECOVERY_TARGET_XID)
{ {
/* /*
* there can be only one transaction end record with this exact * there can be only one transaction end record with this exact
...@@ -5665,17 +5680,14 @@ StartupXLOG(void) ...@@ -5665,17 +5680,14 @@ StartupXLOG(void)
if (StandbyMode) if (StandbyMode)
ereport(LOG, ereport(LOG,
(errmsg("entering standby mode"))); (errmsg("entering standby mode")));
else if (recoveryTarget) else if (recoveryTarget == RECOVERY_TARGET_XID)
{ ereport(LOG,
if (recoveryTargetExact) (errmsg("starting point-in-time recovery to XID %u",
ereport(LOG, recoveryTargetXid)));
(errmsg("starting point-in-time recovery to XID %u", else if (recoveryTarget == RECOVERY_TARGET_TIME)
recoveryTargetXid))); ereport(LOG,
else (errmsg("starting point-in-time recovery to %s",
ereport(LOG, timestamptz_to_str(recoveryTargetTime))));
(errmsg("starting point-in-time recovery to %s",
timestamptz_to_str(recoveryTargetTime))));
}
else else
ereport(LOG, ereport(LOG,
(errmsg("starting archive recovery"))); (errmsg("starting archive recovery")));
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.103 2010/02/26 02:01:21 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.104 2010/03/19 11:05:15 sriggs Exp $
*/ */
#ifndef XLOG_H #ifndef XLOG_H
#define XLOG_H #define XLOG_H
...@@ -172,6 +172,17 @@ extern HotStandbyState standbyState; ...@@ -172,6 +172,17 @@ extern HotStandbyState standbyState;
#define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING) #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
/*
* Recovery target type.
* Only set during a Point in Time recovery, not when standby_mode = on
*/
typedef enum
{
RECOVERY_TARGET_UNSET,
RECOVERY_TARGET_XID,
RECOVERY_TARGET_TIME
} RecoveryTargetType;
extern XLogRecPtr XactLastRecEnd; extern XLogRecPtr XactLastRecEnd;
/* these variables are GUC parameters related to XLOG */ /* these variables are GUC parameters related to XLOG */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment