pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: katsumata.tomonari@po.ntts.co.jp
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8686: Standby could not restart.
Date: Fri, 20 Dec 2013 18:15:09 +0200
Message-ID: <52B46D0D.2070505@vmware.com> (raw)
In-Reply-To: <E1VtTni-00082E-Jv@wrigleys.postgresql.org>
References: <E1VtTni-00082E-Jv@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 12/19/2013 04:57 AM, katsumata.tomonari@po.ntts.co.jp wrote:
> At first, I doubted the recovery state reached "consistent" before redo
> starts.
> And then I checked pg_control and related WAL.
> The WAL sequence is like below.
>
>
> WAL--(a)--(b)--(c)--(d)--(e)-->
> ================================================
> (a) Latest checkpoint's REDO location
> 1/783B230
>
>
> (b) hot_update
> 1/7842010
>
>
> (c) truncate
> 1/8E7E5C8
>
>
> (d) Latest checkpoint location
> 1/8E7F0B0
>
>
> (e) Minimum recovery ending location
> 1/8E7F110
> ================================================
>
>
>>From these things, I found it has happened with this scenario.
> ----------
> (1) standby starting
> (2) seeking checkpoint location 1/8E7F0B0 because backup_label is not
> absecnt
> (3) reachedConsistency is set to true at 1/8E7F110 in
> CheckRecoveryConsistent
> (4) redo start from 1/783B230
> (5) PANIC at 1/7842010 because reachedConsistency has set already and
> operating against a block which will be truncated at (c).
> ----------
>
> At step(2), EndRecPtr is set to 1/8E7F110(next to 1/8E7F0B0),
> so reachedConsistency is set to true at step(3).

Yep. Thanks for a good explanation.

> I think it's not need to increase EndRecPtr while seeking checkpoint
> location.
> I tried to revise it and this worked fine.

Hmm. There's this comment in StartupXLOG, after reading the checkpoint 
record, but before reading the first record at REDO point:


> 		/*
> 		 * Initialize shared replayEndRecPtr, lastReplayedEndRecPtr, and
> 		 * recoveryLastXTime.
> 		 *
> 		 * This is slightly confusing if we're starting from an online
> 		 * checkpoint; we've just read and replayed the checkpoint record, but
> 		 * we're going to start replay from its redo pointer, which precedes
> 		 * the location of the checkpoint record itself. So even though the
> 		 * last record we've replayed is indeed ReadRecPtr, we haven't
> 		 * replayed all the preceding records yet. That's OK for the current
> 		 * use of these variables.
> 		 */
> 		SpinLockAcquire(&xlogctl->info_lck);
> 		xlogctl->replayEndRecPtr = ReadRecPtr;
> 		xlogctl->lastReplayedEndRecPtr = EndRecPtr;
> 		xlogctl->recoveryLastXTime = 0;
> 		xlogctl->currentChunkStartTime = 0;
> 		xlogctl->recoveryPause = false;
> 		SpinLockRelease(&xlogctl->info_lck);

I think we need to fix that confusion. Your patch will do it by not 
setting EndRecPtr yet; that fixes the bug, but leaves those variables in 
a slightly strange state; I'm not sure what EndRecPtr points to in that 
case (0 ?), but ReadRecPtr would be set I guess.

Perhaps we should reset replayEndRecPtr and lastReplayedEndRecPtr to the 
REDO point here, instead of ReadRecPtr/EndRecPtr.

- Heikki


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (7+ messages)  latest in thread

Message-ID: <52B46D0D.2070505@vmware.com>
Permalink:  ../52B46D0D.2070505@vmware.com/
Also on:    postgresql.org/message-id/52B46D0D.2070505@vmware.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: hlinnakangas@vmware.com, katsumata.tomonari@po.ntts.co.jp
  Subject: Re: BUG #8686: Standby could not restart.
  In-Reply-To: <52B46D0D.2070505@vmware.com>
  References: <E1VtTni-00082E-Jv@wrigleys.postgresql.org> <52B46D0D.2070505@vmware.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox