]> granicus.if.org Git - postgresql/commit
Fix logic to skip checkpoint if no records have been inserted.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 15 Apr 2015 14:21:04 +0000 (17:21 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 15 Apr 2015 14:21:04 +0000 (17:21 +0300)
commit3d80a1e0e3e278edc6022d642478dcbd089d4483
tree270b9d2c0dc076ac10d5cc535df63dbe9a273b89
parent9fa8b0ee90c44c0f97d16bf65e94322988c94864
Fix logic to skip checkpoint if no records have been inserted.

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.
src/backend/access/transam/xlog.c