• Heikki Linnakangas's avatar
    Fix logic to skip checkpoint if no records have been inserted. · 3d80a1e0
    Heikki Linnakangas authored
    After the WAL format changes, the calculation of the size of a checkpoint
    record became incorrect. Instead of trying to fix the math, check that the
    previous record, i.e. the xl_prev value that we'd write for the next
    record, matches the last checkpoint's redo pointer. That way it's not
    dependent on the size of the checkpoint record at all.
    
    The old logic was actually slightly wrong all along: if the previous
    checkpoint record crossed a page boundary, the page headers threw off the
    record size calculation, and the checkpoint was not skipped. The new
    checkpoint would not cross a page boundary, so this only resulted in at
    most one extra checkpoint after the system became idle. The new logic fixes
    that. (It's not worth fixing in backbranches).
    
    However, it makes some sense to try to keep the latest checkpoint contained
    fully in a page, or at least in a single WAL segment, just on general
    robustness grounds. If something goes awfully wrong, it's more likely that
    you can recover the latest WAL segment, than the last two WAL segments. So
    I added an extra check that the checkpoint is not skipped if the previous
    checkpoint crossed a WAL segment.
    
    Reported by Jeff Janes.
    3d80a1e0
xlog.c 343 KB