• Heikki Linnakangas's avatar
    Refactor checking whether we've reached the recovery target. · c945af80
    Heikki Linnakangas authored
    Makes the replay loop slightly more readable, by separating the concerns of
    whether to stop and whether to delay, and how to extract the timestamp from
    a record.
    
    This has the user-visible change that the timestamp of the last applied
    record is now updated after actually applying it. Before, it was updated
    just before applying it. That meant that pg_last_xact_replay_timestamp()
    could return the timestamp of a commit record that is in process of being
    replayed, but not yet applied. Normally the difference is small, but if
    min_recovery_apply_delay is set, there could be a significant delay between
    reading a record and applying it.
    
    Another behavioral change is that if you recover to a restore point, we stop
    after the restore point record, not before it. It makes no difference as far
    as running queries on the server is concerned, as applying a restore point
    record changes nothing, but if examine the timeline history you will see
    that the new timeline branched off just after the restore point record, not
    before it. One practical consequence is that if you do PITR to the new
    timeline, and set recovery target to the same named restore point again, it
    will find and stop recovery at the same restore point. Conceptually, I think
    it makes more sense to consider the restore point as part of the new
    timeline's history than not.
    
    In principle, setting the last-replayed timestamp before actually applying
    the record was a bug all along, but it doesn't seem worth the risk to
    backpatch, since min_recovery_apply_delay was only added in 9.4.
    c945af80
xlog.c 346 KB