Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UMyBN-0003bo-Id for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Apr 2013 10:11:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UMyBN-0007w6-0Z for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Apr 2013 10:11:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UMyBM-0007w1-GK for pgsql-bugs@postgresql.org; Tue, 02 Apr 2013 10:11:12 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UMyB9-0002TX-JI for pgsql-bugs@postgresql.org; Tue, 02 Apr 2013 10:11:12 +0000 Received: from intern.anarazel.de (unknown [89.204.130.37]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 3709A4E8002; Tue, 2 Apr 2013 12:10:30 +0200 (CEST) Date: Tue, 2 Apr 2013 12:10:12 +0200 From: Andres Freund To: Simon Riggs Cc: Sergey Konoplev , pgsql-bugs@postgresql.org, Maxim Boguk , =?utf-8?B?0JzQsNC60YHQuNC8INCf0LDQvdGH0LXQvdC60L4=?= , =?utf-8?B?0KLQvtC70YHRgtC10L3QutC+INCY0LvRjNGP?= Subject: Re: Completely broken replica after PANIC: WAL contains references to invalid pages Message-ID: <20130402101012.GB2415@alap2.anarazel.de> References: <675b7cee-b7f0-4e32-8e34-1efaf3ca5fe9@email.android.com> <20130329213834.GA26976@awork2.anarazel.de> <20130330172144.GI28736@alap2.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -1.8 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2013-04-01 08:49:16 +0100, Simon Riggs wrote: > On 30 March 2013 17:21, Andres Freund wrote: > > > 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. > > That was an old bug. > > StartupSUBTRANS() now explicitly fills that gap. Are you saying it > does that incorrectly? How? Well, no. I think StartupSUBTRANS does this correctly, but there's a gap between the call to Startup* and the first call to ExtendSUBTRANS. The latter is only called *after* we reached STANDBY_INITIALIZED via ProcArrayApplyRecoveryInfo(). The problem is that we StartupSUBTRANS to checkPoint.oldestActiveXid while we start to ExtendSUBTRANS from running->nextXid - 1. There very well can be a gap inbetween. The window isn't terribly big but if you use subtransactions as heavily as Sergey seems to be it doesn't seem unlikely to hit it. Let me come up with a testcase and patch. 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