From: Andres Freund <andres@2ndquadrant.com>
To: Sergey Konoplev <gray.ru@gmail.com>
Cc: pgsql-bugs@postgresql.org
Cc: Maxim Boguk <maxim.boguk@gmail.com>
Cc: Максим Панченко <Panchenko@gw.tander.ru>
Cc: Толстенко Илья <tolstenko_iv@gw.tander.ru>
Subject: Re: Completely broken replica after PANIC: WAL contains references to invalid pages
Date: Sat, 30 Mar 2013 18:21:44 +0100
Message-ID: <20130330172144.GI28736@alap2.anarazel.de> (raw)
In-Reply-To: <CAL_0b1sJHOwmSDRkP8a8QFKVDTrvEkxN_LfD-GaBSPS4LC2v_w@mail.gmail.com>
References: <CAL_0b1t=WuM6roO8dki=w8DhH8P8whhohbPjReymmQUrOcNT2A@mail.gmail.com>
<675b7cee-b7f0-4e32-8e34-1efaf3ca5fe9@email.android.com>
<CAL_0b1vLSGx=ENLkSK1cyDtGcYVAb_im051w-bza3H-7dPgTBA@mail.gmail.com>
<20130329213834.GA26976@awork2.anarazel.de>
<CAL_0b1sJHOwmSDRkP8a8QFKVDTrvEkxN_LfD-GaBSPS4LC2v_w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 2013-03-29 14:53:26 -0700, Sergey Konoplev wrote:
> On Fri, Mar 29, 2013 at 2:38 PM, Andres Freund <andres@2ndquadrant.com> wrote:
> > I have to admit, I find it a bit confusing that so many people report a
> > bug and then immediately destroy all evidence of the bug. Just seems to
> > a happen a bit too frequently.
>
> You see, businesses usually need it up ASAP again. Sorry, I must have
> note down the output of pg_controldata straight after it got broken, I
> just have not came up to it.
But the business will also need the standby working correctly in case
of a critical incident of a primary. So it should have quite an interest
in fixing bugs in that area. Yes, I realize thats not always easy to do
:(.
> > Thats not a pg_controldata output from the broken replica though, or is
> > it? I guess its from a new standby?
>
> That was the output from the standby that was rsync-ed on top of the
> broken one. I thought you might find something useful in it.
> Can I test your guess some other way? And what was the guess?
Don't think you can easily test it. And after reading more code I am
pretty sure my original guess was bogus. As was my second. And third ;)
But I think I see what could be going on:
During HS we maintain pg_subtrans so we can deal with more than
PGPROC_MAX_CACHED_SUBXIDS in one TX. For that we need to regularly
extend subtrans so the pages are initialized when we setup the
topxid<->subxid mapping in ProcArrayApplyXidAssignment(). The call to
ExtendSUBTRANS happens in RecordKnownAssignedTransactionIds() which is
called from several places, including ProcArrayApplyXidAssignment().
The logic it uses is:
if (TransactionIdFollows(xid, latestObservedXid))
{
TransactionId next_expected_xid;
/*
* Extend clog and subtrans like we do in GetNewTransactionId() during
* normal operation using individual extend steps. Typical case
* requires almost no activity.
*/
next_expected_xid = latestObservedXid;
TransactionIdAdvance(next_expected_xid);
while (TransactionIdPrecedesOrEquals(next_expected_xid, xid))
{
ExtendCLOG(next_expected_xid);
ExtendSUBTRANS(next_expected_xid);
TransactionIdAdvance(next_expected_xid);
}
So if the xid is later than latestObservedXid we extend subtrans one by
one. So far so good. But we initialize it in
ProcArrayApplyRecoveryInfo() when consistency is initially reached:
latestObservedXid = running->nextXid;
TransactionIdRetreat(latestObservedXid);
Before that subtrans has initially been started up with:
if (wasShutdown)
oldestActiveXID = PrescanPreparedTransactions(&xids, &nxids);
else
oldestActiveXID = checkPoint.oldestActiveXid;
...
StartupSUBTRANS(oldestActiveXID);
That means its only initialized up to checkPoint.oldestActiveXid. As it
can take some time till we reach consistency it seems rather plausible
that there now will be a gap in initilized pages. From
checkPoint.oldestActiveXid to running->nextXid if there are pages
inbetween.
Does that explanation sound about right to anybody else? I'll provide a
patch for the issue in a while, for now I'll try to reproduce it.
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: andres@2ndquadrant.com, gray.ru@gmail.com, maxim.boguk@gmail.com, Panchenko@gw.tander.ru, tolstenko_iv@gw.tander.ru
Subject: Re: Completely broken replica after PANIC: WAL contains references to invalid pages
In-Reply-To: <20130330172144.GI28736@alap2.anarazel.de>
References: <CAL_0b1t=WuM6roO8dki=w8DhH8P8whhohbPjReymmQUrOcNT2A@mail.gmail.com> <675b7cee-b7f0-4e32-8e34-1efaf3ca5fe9@email.android.com> <CAL_0b1vLSGx=ENLkSK1cyDtGcYVAb_im051w-bza3H-7dPgTBA@mail.gmail.com> <20130329213834.GA26976@awork2.anarazel.de> <CAL_0b1sJHOwmSDRkP8a8QFKVDTrvEkxN_LfD-GaBSPS4LC2v_w@mail.gmail.com> <20130330172144.GI28736@alap2.anarazel.de>
* 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