Skip site navigation (1) Skip section navigation (2)

pgsql: Consistency check should compare last record replayed,not last

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Consistency check should compare last record replayed,not last
Date: 2012-12-11 16:59:39
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-committers
Consistency check should compare last record replayed, not last record read.

EndRecPtr is the last record that we've read, but not necessarily yet
replayed. CheckRecoveryConsistency should compare minRecoveryPoint with the
last replayed record instead. This caused recovery to think it's reached
consistency too early.

Now that we do the check in CheckRecoveryConsistency correctly, we have to
move the call of that function to after redoing a record. The current place,
after reading a record but before replaying it, is wrong. In particular, if
there are no more records after the one ending at minRecoveryPoint, we don't
enter hot standby until one extra record is generated and read by the
standby, and CheckRecoveryConsistency is called. These two bugs conspired
to make the code appear to work correctly, except for the small window
between reading the last record that reaches minRecoveryPoint, and
replaying it.

In the passing, rename recoveryLastRecPtr, which is the last record
replayed, to lastReplayedEndRecPtr. This makes it slightly less confusing
with replayEndRecPtr, which is the last record read that we're about to

Original report from Kyotaro HORIGUCHI, further diagnosis by Fujii Masao.
Backpatch to 9.0, where Hot Standby subtly changed the test from
"minRecoveryPoint < EndRecPtr" to "minRecoveryPoint <= EndRecPtr". The
former works because where the test is performed, we have always read one
more record than we've replayed.



Modified Files
src/backend/access/transam/xlog.c |   33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)

pgsql-committers by date

Next:From: Bruce MomjianDate: 2012-12-11 20:09:31
Subject: pgsql: Fix pg_upgrade for invalid indexes
Previous:From: Heikki LinnakangasDate: 2012-12-11 16:59:38
Subject: pgsql: Consistency check should compare last record replayed,not last

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group