diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index a59a0e826b..d354701423 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -3023,19 +3023,6 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode, record = XLogPrefetcherReadRecord(xlogprefetcher, &errormsg); if (record == NULL) { - /* - * When not in standby mode we find that WAL ends in an incomplete - * record, keep track of that record. After recovery is done, - * we'll write a record to indicate to downstream WAL readers that - * that portion is to be ignored. - */ - if (!StandbyMode && - !XLogRecPtrIsInvalid(xlogreader->abortedRecPtr)) - { - abortedRecPtr = xlogreader->abortedRecPtr; - missingContrecPtr = xlogreader->missingContrecPtr; - } - if (readFile >= 0) { close(readFile); @@ -3125,8 +3112,20 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode, /* In standby mode, loop back to retry. Otherwise, give up. */ if (StandbyMode && !CheckForStandbyTrigger()) continue; - else - return NULL; + + /* + * We return NULL to the caller. If the last record has failed + * with a missing contrecord, inform that to the caller as well. + * In other cases we retry from the beginning of the failed record + * so no need to do this. + */ + if (!XLogRecPtrIsInvalid(xlogreader->abortedRecPtr)) + { + abortedRecPtr = xlogreader->abortedRecPtr; + missingContrecPtr = xlogreader->missingContrecPtr; + } + + return NULL; } } }