diff -rpcd a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c *** a/src/backend/access/transam/xlog.c 2013-12-02 09:17:05.000000000 +0900 --- b/src/backend/access/transam/xlog.c 2013-12-16 11:25:29.000000000 +0900 *************** XLogFileRead(XLogSegNo segno, int emode, *** 3763,3771 **** /* * If the segment was fetched from archival storage, replace the existing ! * xlog segment (if any) with the archival version. */ ! if (source == XLOG_FROM_ARCHIVE) { KeepFileRestoredFromArchive(path, xlogfname); --- 3763,3772 ---- /* * If the segment was fetched from archival storage, replace the existing ! * xlog segment (if any) with the archival version. This is necessary for ! * cascading replication in 9.2 and fast promotion in 9.3. */ ! if (source == XLOG_FROM_ARCHIVE && StandbyModeRequested) { KeepFileRestoredFromArchive(path, xlogfname); *************** exitArchiveRecovery(TimeLineID endTLI, X *** 5561,5582 **** } /* ! * If we are establishing a new timeline, we have to copy data from the ! * last WAL segment of the old timeline to create a starting WAL segment ! * for the new timeline. * ! * Notify the archiver that the last WAL segment of the old timeline is ! * ready to copy to archival storage. Otherwise, it is not archived for a ! * while. */ ! if (endTLI != ThisTimeLineID) { ! XLogFileCopy(endLogSegNo, endTLI, endLogSegNo); ! if (XLogArchivingActive()) { ! XLogFileName(xlogpath, endTLI, endLogSegNo); ! XLogArchiveNotify(xlogpath); } } --- 5562,5622 ---- } /* ! * If the segment was fetched from archival storage, we want to replace ! * the existing xlog segment (if any) with the archival version. This is ! * because whatever is in XLOGDIR is very possibly older than what we have ! * from the archives, since it could have come from restoring a PGDATA ! * backup. In any case, the archival version certainly is more ! * descriptive of what our current database state is, because that is what ! * we replayed from. * ! * Note that if we are establishing a new timeline, ThisTimeLineID is ! * already set to the new value, and so we will create a new file instead ! * of overwriting any existing file. (This is, in fact, always the case ! * at present.) */ ! snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG"); ! XLogFilePath(xlogpath, ThisTimeLineID, endLogSegNo); ! ! if (restoredFromArchive) { ! ereport(DEBUG3, ! (errmsg_internal("moving last restored xlog to \"%s\"", ! xlogpath))); ! unlink(xlogpath); /* might or might not exist */ ! if (rename(recoveryPath, xlogpath) != 0) ! ereport(FATAL, ! (errcode_for_file_access(), ! errmsg("could not rename file \"%s\" to \"%s\": %m", ! recoveryPath, xlogpath))); ! /* XXX might we need to fix permissions on the file? */ ! } ! else ! { ! /* ! * If the latest segment is not archival, but there's still a ! * RECOVERYXLOG laying about, get rid of it. ! */ ! unlink(recoveryPath); /* ignore any error */ ! /* ! * If we are establishing a new timeline, we have to copy data from ! * the last WAL segment of the old timeline to create a starting WAL ! * segment for the new timeline. ! * ! * Notify the archiver that the last WAL segment of the old timeline ! * is ready to copy to archival storage. Otherwise, it is not archived ! * for a while. ! */ ! if (endTLI != ThisTimeLineID) { ! XLogFileCopy(endLogSegNo, endTLI, endLogSegNo); ! ! if (XLogArchivingActive()) ! { ! XLogFileName(xlogpath, endTLI, endLogSegNo); ! XLogArchiveNotify(xlogpath); ! } } } *************** exitArchiveRecovery(TimeLineID endTLI, X *** 5587,5599 **** XLogFileName(xlogpath, ThisTimeLineID, endLogSegNo); XLogArchiveCleanup(xlogpath); - /* - * Since there might be a partial WAL segment named RECOVERYXLOG, get rid - * of it. - */ - snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYXLOG"); - unlink(recoveryPath); /* ignore any error */ - /* Get rid of any remaining recovered timeline-history file, too */ snprintf(recoveryPath, MAXPGPATH, XLOGDIR "/RECOVERYHISTORY"); unlink(recoveryPath); /* ignore any error */ --- 5627,5632 ----