diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2010-03-19 11:05:15 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2010-03-19 11:05:15 +0000 |
commit | 3cdafe40e73c0c565e54fdaf69fe35f294906693 (patch) | |
tree | 3def408cf1c3d0377c6c9b470e2f7cd0cdccfd9e /src | |
parent | 5c73ae17d18a424fe63c0a1d8b674e9f22800572 (diff) | |
download | postgresql-3cdafe40e73c0c565e54fdaf69fe35f294906693.tar.gz postgresql-3cdafe40e73c0c565e54fdaf69fe35f294906693.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/transam/xlog.c | 70 | ||||
-rw-r--r-- | src/include/access/xlog.h | 13 |
2 files changed, 53 insertions, 30 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 0d70cf9b202..29d64f0ff84 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * 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; static char *recoveryRestoreCommand = NULL; static char *recoveryEndCommand = NULL; static char *restartPointCommand = NULL; -static bool recoveryTarget = false; -static bool recoveryTargetExact = false; +static RecoveryTargetType recoveryTarget = RECOVERY_TARGET_UNSET; static bool recoveryTargetInclusive = true; static TransactionId recoveryTargetXid; static TimestampTz recoveryTargetTime; @@ -4224,14 +4223,32 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, */ XLogFileName(xlogfname, endTLI, endLogId, endLogSeg); - snprintf(buffer, sizeof(buffer), - "%s%u\t%s\t%s transaction %u at %s\n", - (srcfd < 0) ? "" : "\n", - parentTLI, - xlogfname, - recoveryStopAfter ? "after" : "before", - recoveryStopXid, - timestamptz_to_str(recoveryStopTime)); + /* + * Write comment to history file to explain why and where timeline changed. + * Comment varies according to the recovery target used. + */ + if (recoveryTarget == RECOVERY_TARGET_XID) + snprintf(buffer, sizeof(buffer), + "%s%u\t%s\t%s transaction %u\n", + (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); errno = 0; @@ -4978,8 +4995,7 @@ readRecoveryCommandFile(void) ereport(DEBUG2, (errmsg("recovery_target_xid = %u", recoveryTargetXid))); - recoveryTarget = true; - recoveryTargetExact = true; + recoveryTarget = RECOVERY_TARGET_XID; } else if (strcmp(tok1, "recovery_target_time") == 0) { @@ -4987,10 +5003,9 @@ readRecoveryCommandFile(void) * if recovery_target_xid specified, then this overrides * recovery_target_time */ - if (recoveryTargetExact) + if (recoveryTarget == RECOVERY_TARGET_XID) continue; - recoveryTarget = true; - recoveryTargetExact = false; + recoveryTarget = RECOVERY_TARGET_TIME; /* * Convert the time string given by the user to TimestampTz form. @@ -5265,13 +5280,13 @@ recoveryStopsHere(XLogRecord *record, bool *includeThis) return false; /* Do we have a PITR target at all? */ - if (!recoveryTarget) + if (recoveryTarget == RECOVERY_TARGET_UNSET) { recoveryLastXTime = recordXtime; return false; } - if (recoveryTargetExact) + if (recoveryTarget == RECOVERY_TARGET_XID) { /* * there can be only one transaction end record with this exact @@ -5665,17 +5680,14 @@ StartupXLOG(void) if (StandbyMode) ereport(LOG, (errmsg("entering standby mode"))); - else if (recoveryTarget) - { - if (recoveryTargetExact) - ereport(LOG, - (errmsg("starting point-in-time recovery to XID %u", - recoveryTargetXid))); - else - ereport(LOG, - (errmsg("starting point-in-time recovery to %s", - timestamptz_to_str(recoveryTargetTime)))); - } + else if (recoveryTarget == RECOVERY_TARGET_XID) + ereport(LOG, + (errmsg("starting point-in-time recovery to XID %u", + recoveryTargetXid))); + else if (recoveryTarget == RECOVERY_TARGET_TIME) + ereport(LOG, + (errmsg("starting point-in-time recovery to %s", + timestamptz_to_str(recoveryTargetTime)))); else ereport(LOG, (errmsg("starting archive recovery"))); diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 58139112501..9a6cd107614 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * 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 #define XLOG_H @@ -172,6 +172,17 @@ extern HotStandbyState standbyState; #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; /* these variables are GUC parameters related to XLOG */ |