pgsql: Fix transient clobbering of shared buffers during WAL replay. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix transient clobbering of shared buffers during WAL replay.
Date
Msg-id E1Ru93F-0002h5-Kk@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix transient clobbering of shared buffers during WAL replay.

RestoreBkpBlocks was in the habit of zeroing and refilling the target
buffer; which was perfectly safe when the code was written, but is unsafe
during Hot Standby operation.  The reason is that we have coding rules
that allow backends to continue accessing a tuple in a heap relation while
holding only a pin on its buffer.  Such a backend could see transiently
zeroed data, if WAL replay had occasion to change other data on the page.
This has been shown to be the cause of bug #6425 from Duncan Rance (who
deserves kudos for developing a sufficiently-reproducible test case) as
well as Bridget Frey's re-report of bug #6200.  It most likely explains the
original report as well, though we don't yet have confirmation of that.

To fix, change the code so that only bytes that are supposed to change will
change, even transiently.  This actually saves cycles in RestoreBkpBlocks,
since it's not writing the same bytes twice.

Also fix seq_redo, which has the same disease, though it has to work a bit
harder to meet the requirement.

So far as I can tell, no other WAL replay routines have this type of bug.
In particular, the index-related replay routines, which would certainly be
broken if they had to meet the same standard, are not at risk because we
do not have coding rules that allow access to an index page when not
holding a buffer lock on it.

Back-patch to 9.0 where Hot Standby was added.

Branch
------
REL9_0_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/2b196f01efd8ef4f5178d52d1e27cd79747e9568

Modified Files
--------------
src/backend/access/transam/xlog.c |    4 ++--
src/backend/commands/sequence.c   |   29 ++++++++++++++++++++++-------
2 files changed, 24 insertions(+), 9 deletions(-)


pgsql-committers by date:

Previous
From: Bernd Helmle
Date:
Subject: Re: pgsql: Applied Peter's patch to PQconnectdbParams in ecpglib instead of
Next
From: Tom Lane
Date:
Subject: pgsql: Fix transient clobbering of shared buffers during WAL replay.