Fix WAL-logging of FSM and VM truncation.
authorHeikki Linnakangas
Wed, 19 Oct 2016 11:43:34 +0000 (14:43 +0300)
committerHeikki Linnakangas
Wed, 19 Oct 2016 12:00:10 +0000 (15:00 +0300)
commit2523bef15e446d25d16b206bac3b6ef6ad6a8a7d
tree511f732c95c42ab65ecd4f2a492aa49ecafae4f8
parentad8cd4baa3a451887b22b104b2dc2f53133537d4
Fix WAL-logging of FSM and VM truncation.

When a relation is truncated, it is important that the FSM is truncated as
well. Otherwise, after recovery, the FSM can return a page that has been
truncated away, leading to errors like:

ERROR:  could not read block 28991 in file "base/16390/572026": read only 0
of 8192 bytes

We were using MarkBufferDirtyHint() to dirty the buffer holding the last
remaining page of the FSM, but during recovery, that might in fact not
dirty the page, and the FSM update might be lost.

To fix, use the stronger MarkBufferDirty() function. MarkBufferDirty()
requires us to do WAL-logging ourselves, to protect from a torn page, if
checksumming is enabled.

Also fix an oversight in visibilitymap_truncate: it also needs to WAL-log
when checksumming is enabled.

Analysis by Pavan Deolasee.

Discussion: 

Backpatch to 9.3, where we got data checksums.
src/backend/access/heap/visibilitymap.c
src/backend/storage/freespace/freespace.c