|
7 | 7 | * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 |
| - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.282 2007/09/26 22:36:30 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.283 2007/09/29 01:36:10 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -4518,7 +4518,8 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
|
4518 | 4518 | *
|
4519 | 4519 | * Note that if we are establishing a new timeline, ThisTimeLineID is
|
4520 | 4520 | * already set to the new value, and so we will create a new file instead
|
4521 |
| - * of overwriting any existing file. |
| 4521 | + * of overwriting any existing file. (This is, in fact, always the case |
| 4522 | + * at present.) |
4522 | 4523 | */
|
4523 | 4524 | snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG");
|
4524 | 4525 | XLogFilePath(xlogpath, ThisTimeLineID, endLogId, endLogSeg);
|
@@ -4700,7 +4701,7 @@ StartupXLOG(void)
|
4700 | 4701 | XLogCtlInsert *Insert;
|
4701 | 4702 | CheckPoint checkPoint;
|
4702 | 4703 | bool wasShutdown;
|
4703 |
| - bool needNewTimeLine = false; |
| 4704 | + bool reachedStopPoint = false; |
4704 | 4705 | bool haveBackupLabel = false;
|
4705 | 4706 | XLogRecPtr RecPtr,
|
4706 | 4707 | LastRec,
|
@@ -5010,7 +5011,7 @@ StartupXLOG(void)
|
5010 | 5011 | */
|
5011 | 5012 | if (recoveryStopsHere(record, &recoveryApply))
|
5012 | 5013 | {
|
5013 |
| - needNewTimeLine = true; /* see below */ |
| 5014 | + reachedStopPoint = true; /* see below */ |
5014 | 5015 | recoveryContinue = false;
|
5015 | 5016 | if (!recoveryApply)
|
5016 | 5017 | break;
|
@@ -5078,24 +5079,29 @@ StartupXLOG(void)
|
5078 | 5079 | */
|
5079 | 5080 | if (XLByteLT(EndOfLog, ControlFile->minRecoveryPoint))
|
5080 | 5081 | {
|
5081 |
| - if (needNewTimeLine) /* stopped because of stop request */ |
| 5082 | + if (reachedStopPoint) /* stopped because of stop request */ |
5082 | 5083 | ereport(FATAL,
|
5083 | 5084 | (errmsg("requested recovery stop point is before end time of backup dump")));
|
5084 |
| - else |
5085 |
| - /* ran off end of WAL */ |
| 5085 | + else /* ran off end of WAL */ |
5086 | 5086 | ereport(FATAL,
|
5087 | 5087 | (errmsg("WAL ends before end time of backup dump")));
|
5088 | 5088 | }
|
5089 | 5089 |
|
5090 | 5090 | /*
|
5091 | 5091 | * Consider whether we need to assign a new timeline ID.
|
5092 | 5092 | *
|
5093 |
| - * If we stopped short of the end of WAL during recovery, then we are |
5094 |
| - * generating a new timeline and must assign it a unique new ID. |
5095 |
| - * Otherwise, we can just extend the timeline we were in when we ran out |
5096 |
| - * of WAL. |
| 5093 | + * If we are doing an archive recovery, we always assign a new ID. This |
| 5094 | + * handles a couple of issues. If we stopped short of the end of WAL |
| 5095 | + * during recovery, then we are clearly generating a new timeline and must |
| 5096 | + * assign it a unique new ID. Even if we ran to the end, modifying the |
| 5097 | + * current last segment is problematic because it may result in trying |
| 5098 | + * to overwrite an already-archived copy of that segment, and we encourage |
| 5099 | + * DBAs to make their archive_commands reject that. We can dodge the |
| 5100 | + * problem by making the new active segment have a new timeline ID. |
| 5101 | + * |
| 5102 | + * In a normal crash recovery, we can just extend the timeline we were in. |
5097 | 5103 | */
|
5098 |
| - if (needNewTimeLine) |
| 5104 | + if (InArchiveRecovery) |
5099 | 5105 | {
|
5100 | 5106 | ThisTimeLineID = findNewestTimeLine(recoveryTargetTLI) + 1;
|
5101 | 5107 | ereport(LOG,
|
|
0 commit comments