Skip to content

Commit

Permalink
Log the correct ending timestamp in recovery_target_xid mode.
Browse files Browse the repository at this point in the history
When ending recovery based on recovery_target_xid matching with
recovery_target_inclusive = off, we printed an incorrect timestamp
(always 2000-01-01) in the "recovery stopping before ... transaction"
log message.  This is a consequence of sloppy refactoring in
c945af8: the code to fetch recordXtime out of the commit/abort
record used to be executed unconditionally, but it was changed
to get called only in the RECOVERY_TARGET_TIME case.  We need only
flip the order of operations to restore the intended behavior.

Per report from Torsten Förtsch.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/CAKkG4_kUevPqbmyOfLajx7opAQk6Cvwkvx0HRcFjSPfRPTXanA@mail.gmail.com
  • Loading branch information
tglsfdc committed Jan 19, 2023
1 parent fed4e92 commit 1b9a0b9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/backend/access/transam/xlog.c
Expand Up @@ -5833,8 +5833,13 @@ recoveryStopsBefore(XLogReaderState *record)
stopsHere = (recordXid == recoveryTargetXid);
}

if (recoveryTarget == RECOVERY_TARGET_TIME &&
getRecordTimestamp(record, &recordXtime))
/*
* Note: we must fetch recordXtime regardless of recoveryTarget setting.
* We don't expect getRecordTimestamp ever to fail, since we already know
* this is a commit or abort record; but test its result anyway.
*/
if (getRecordTimestamp(record, &recordXtime) &&
recoveryTarget == RECOVERY_TARGET_TIME)
{
/*
* There can be many transactions that share the same commit time, so
Expand Down

0 comments on commit 1b9a0b9

Please sign in to comment.