Skip to content

Commit 3cdafe4

Browse files
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.
1 parent 5c73ae1 commit 3cdafe4

File tree

2 files changed

+53
-30
lines changed

2 files changed

+53
-30
lines changed

src/backend/access/transam/xlog.c

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.382 2010/03/18 09:17:18 heikki Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.383 2010/03/19 11:05:14 sriggs Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -172,8 +172,7 @@ static bool restoredFromArchive = false;
172172
static char *recoveryRestoreCommand = NULL;
173173
static char *recoveryEndCommand = NULL;
174174
static char *restartPointCommand = NULL;
175-
static bool recoveryTarget = false;
176-
static bool recoveryTargetExact = false;
175+
static RecoveryTargetType recoveryTarget = RECOVERY_TARGET_UNSET;
177176
static bool recoveryTargetInclusive = true;
178177
static TransactionId recoveryTargetXid;
179178
static TimestampTz recoveryTargetTime;
@@ -4224,14 +4223,32 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
42244223
*/
42254224
XLogFileName(xlogfname, endTLI, endLogId, endLogSeg);
42264225

4227-
snprintf(buffer, sizeof(buffer),
4228-
"%s%u\t%s\t%s transaction %u at %s\n",
4229-
(srcfd < 0) ? "" : "\n",
4230-
parentTLI,
4231-
xlogfname,
4232-
recoveryStopAfter ? "after" : "before",
4233-
recoveryStopXid,
4234-
timestamptz_to_str(recoveryStopTime));
4226+
/*
4227+
* Write comment to history file to explain why and where timeline changed.
4228+
* Comment varies according to the recovery target used.
4229+
*/
4230+
if (recoveryTarget == RECOVERY_TARGET_XID)
4231+
snprintf(buffer, sizeof(buffer),
4232+
"%s%u\t%s\t%s transaction %u\n",
4233+
(srcfd < 0) ? "" : "\n",
4234+
parentTLI,
4235+
xlogfname,
4236+
recoveryStopAfter ? "after" : "before",
4237+
recoveryStopXid);
4238+
if (recoveryTarget == RECOVERY_TARGET_TIME)
4239+
snprintf(buffer, sizeof(buffer),
4240+
"%s%u\t%s\t%s %s\n",
4241+
(srcfd < 0) ? "" : "\n",
4242+
parentTLI,
4243+
xlogfname,
4244+
recoveryStopAfter ? "after" : "before",
4245+
timestamptz_to_str(recoveryStopTime));
4246+
else
4247+
snprintf(buffer, sizeof(buffer),
4248+
"%s%u\t%s\tno recovery target specified\n",
4249+
(srcfd < 0) ? "" : "\n",
4250+
parentTLI,
4251+
xlogfname);
42354252

42364253
nbytes = strlen(buffer);
42374254
errno = 0;
@@ -4978,19 +4995,17 @@ readRecoveryCommandFile(void)
49784995
ereport(DEBUG2,
49794996
(errmsg("recovery_target_xid = %u",
49804997
recoveryTargetXid)));
4981-
recoveryTarget = true;
4982-
recoveryTargetExact = true;
4998+
recoveryTarget = RECOVERY_TARGET_XID;
49834999
}
49845000
else if (strcmp(tok1, "recovery_target_time") == 0)
49855001
{
49865002
/*
49875003
* if recovery_target_xid specified, then this overrides
49885004
* recovery_target_time
49895005
*/
4990-
if (recoveryTargetExact)
5006+
if (recoveryTarget == RECOVERY_TARGET_XID)
49915007
continue;
4992-
recoveryTarget = true;
4993-
recoveryTargetExact = false;
5008+
recoveryTarget = RECOVERY_TARGET_TIME;
49945009

49955010
/*
49965011
* Convert the time string given by the user to TimestampTz form.
@@ -5265,13 +5280,13 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis)
52655280
return false;
52665281

52675282
/* Do we have a PITR target at all? */
5268-
if (!recoveryTarget)
5283+
if (recoveryTarget == RECOVERY_TARGET_UNSET)
52695284
{
52705285
recoveryLastXTime = recordXtime;
52715286
return false;
52725287
}
52735288

5274-
if (recoveryTargetExact)
5289+
if (recoveryTarget == RECOVERY_TARGET_XID)
52755290
{
52765291
/*
52775292
* there can be only one transaction end record with this exact
@@ -5665,17 +5680,14 @@ StartupXLOG(void)
56655680
if (StandbyMode)
56665681
ereport(LOG,
56675682
(errmsg("entering standby mode")));
5668-
else if (recoveryTarget)
5669-
{
5670-
if (recoveryTargetExact)
5671-
ereport(LOG,
5672-
(errmsg("starting point-in-time recovery to XID %u",
5673-
recoveryTargetXid)));
5674-
else
5675-
ereport(LOG,
5676-
(errmsg("starting point-in-time recovery to %s",
5677-
timestamptz_to_str(recoveryTargetTime))));
5678-
}
5683+
else if (recoveryTarget == RECOVERY_TARGET_XID)
5684+
ereport(LOG,
5685+
(errmsg("starting point-in-time recovery to XID %u",
5686+
recoveryTargetXid)));
5687+
else if (recoveryTarget == RECOVERY_TARGET_TIME)
5688+
ereport(LOG,
5689+
(errmsg("starting point-in-time recovery to %s",
5690+
timestamptz_to_str(recoveryTargetTime))));
56795691
else
56805692
ereport(LOG,
56815693
(errmsg("starting archive recovery")));

src/include/access/xlog.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.103 2010/02/26 02:01:21 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.104 2010/03/19 11:05:15 sriggs Exp $
1010
*/
1111
#ifndef XLOG_H
1212
#define XLOG_H
@@ -172,6 +172,17 @@ extern HotStandbyState standbyState;
172172

173173
#define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
174174

175+
/*
176+
* Recovery target type.
177+
* Only set during a Point in Time recovery, not when standby_mode = on
178+
*/
179+
typedef enum
180+
{
181+
RECOVERY_TARGET_UNSET,
182+
RECOVERY_TARGET_XID,
183+
RECOVERY_TARGET_TIME
184+
} RecoveryTargetType;
185+
175186
extern XLogRecPtr XactLastRecEnd;
176187

177188
/* these variables are GUC parameters related to XLOG */

0 commit comments

Comments
 (0)