• Michael Paquier's avatar
    Prevent references to invalid relation pages after fresh promotion · 3c64dcb1
    Michael Paquier authored
    If a standby crashes after promotion before having completed its first
    post-recovery checkpoint, then the minimal recovery point which marks
    the LSN position where the cluster is able to reach consistency may be
    set to a position older than the first end-of-recovery checkpoint while
    all the WAL available should be replayed.  This leads to the instance
    thinking that it contains inconsistent pages, causing a PANIC and a hard
    instance crash even if all the WAL available has not been replayed for
    certain sets of records replayed.  When in crash recovery,
    minRecoveryPoint is expected to always be set to InvalidXLogRecPtr,
    which forces the recovery to replay all the WAL available, so this
    commit makes sure that the local copy of minRecoveryPoint from the
    control file is initialized properly and stays as it is while crash
    recovery is performed.  Once switching to archive recovery or if crash
    recovery finishes, then the local copy minRecoveryPoint can be safely
    updated.
    
    Pavan Deolasee has reported and diagnosed the failure in the first
    place, and the base fix idea to rely on the local copy of
    minRecoveryPoint comes from Kyotaro Horiguchi, which has been expanded
    into a full-fledged patch by me.  The test included in this commit has
    been written by Álvaro Herrera and Pavan Deolasee, which I have modified
    to make it faster and more reliable with sleep phases.
    
    Backpatch down to all supported versions where the bug appears, aka 9.3
    which is where the end-of-recovery checkpoint is not run by the startup
    process anymore.  The test gets easily supported down to 10, still it
    has been tested on all branches.
    
    Reported-by: Pavan Deolasee
    Diagnosed-by: Pavan Deolasee
    Reviewed-by: Pavan Deolasee, Kyotaro Horiguchi
    Author: Michael Paquier, Kyotaro Horiguchi, Pavan Deolasee, Álvaro
    Herrera
    Discussion: https://postgr.es/m/CABOikdPOewjNL=05K5CbNMxnNtXnQjhTx2F--4p4ruorCjukbA@mail.gmail.com
    3c64dcb1
015_promotion_pages.pl 3.09 KB