]> granicus.if.org Git - postgresql/commit
In XLogReadBufferExtended, don't assume P_NEW yields consecutive pages.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Feb 2014 19:52:29 +0000 (14:52 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Feb 2014 19:52:29 +0000 (14:52 -0500)
commit7fedd79b71c212d6e83dbe9af75c4ae3c7b89753
treedde0a9571e73f36d256e8b0cee775d12d2b56a23
parente1e7642bd3bdde980c481c5feb7739c4f841f757
In XLogReadBufferExtended, don't assume P_NEW yields consecutive pages.

In a database that's not yet reached consistency, it's possible that some
segments of a relation are not full-size but are not the last ones either.
Because of the way smgrnblocks() works, asking for a new page with P_NEW
will fill in the last not-full-size segment --- and if that makes it full
size, the apparent EOF of the relation will increase by more than one page,
so that the next P_NEW request will yield a page past the next consecutive
one.  This breaks the relation-extension logic in XLogReadBufferExtended,
possibly allowing a page update to be applied to some page far past where
it was intended to go.  This appears to be the explanation for reports of
table bloat on replication slaves compared to their masters, and probably
explains some corrupted-slave reports as well.

Fix the loop to check the page number it actually got, rather than merely
Assert()'ing that dead reckoning got it to the desired place.  AFAICT,
there are no other places that make assumptions about exactly which page
they'll get from P_NEW.

Problem identified by Greg Stark, though this is not the same as his
proposed patch.

It's been like this for a long time, so back-patch to all supported
branches.
src/backend/access/transam/xlogutils.c