Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKwL3-0007AL-EC for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Mar 2013 19:48:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UKwL2-0006oz-Bc for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Mar 2013 19:48:48 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKwL1-0006ot-7G for pgsql-bugs@postgresql.org; Wed, 27 Mar 2013 19:48:47 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UKwKt-0001c5-14 for pgsql-bugs@postgresql.org; Wed, 27 Mar 2013 19:48:45 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 0A13928553; Wed, 27 Mar 2013 12:48:37 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id F1723B035F; Wed, 27 Mar 2013 12:48:36 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id B9C251219CD; Wed, 27 Mar 2013 12:52:39 -0700 (PDT) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-1.vmware.com Received: from zcs-prod-ext-mta-1.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-1.vmware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C_PAbRFYxtS6; Wed, 27 Mar 2013 12:52:39 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 8D98B121993; Wed, 27 Mar 2013 12:52:39 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Wed, 27 Mar 2013 12:52:38 -0700 (PDT) Message-ID: <51534D11.1040704@vmware.com> Date: Wed, 27 Mar 2013 21:48:33 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: Josh Berkus CC: pgsql-bugs@postgresql.org, yjxiao@gmail.com Subject: Re: Re: BUG #7969: Postgres Recovery Fatal With: "incorrect local pin count:2" References: <51533A15.5010408@agliodbs.com> <515342CF.1080805@vmware.com> In-Reply-To: <515342CF.1080805@vmware.com> Content-Type: multipart/mixed; boundary="------------070403020404030207080101" X-Pg-Spam-Score: -8.2 (--------) 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 This is a multi-part message in MIME format. --------------070403020404030207080101 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 27.03.2013 21:04, Heikki Linnakangas wrote: > On 27.03.2013 20:27, Josh Berkus wrote: >> Folks, >> >> So I'm a bit surprised that this bug report hasn't gotten a follow-up. >> Does this sound like the known 9.2.2 corruption issue, or is it >> potentially something else? > > It seems like a new issue. At a quick glance, I think there's a bug in > heap_xlog_update, ie. the redo routine of a heap update. If the new > tuple is put on a different page, and at redo, the new page doesn't > exist (that's normal if it was later vacuumed away), heap_xlog_update > leaks a pin on the old page. Here: > >> { >> nbuffer = XLogReadBuffer(xlrec->target.node, >> ItemPointerGetBlockNumber(&(xlrec->newtid)), >> false); >> if (!BufferIsValid(nbuffer)) >> return; >> page = (Page) BufferGetPage(nbuffer); >> >> if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */ >> { >> UnlockReleaseBuffer(nbuffer); >> if (BufferIsValid(obuffer)) >> UnlockReleaseBuffer(obuffer); >> return; >> } >> } > > Notice how in the first 'return' above, obuffer is not released. > > I'll try to create a reproducible test case for this, and fix.. Ok, here's how to reproduce it: create table foo (i int4 primary key); insert into foo select generate_series(1,1000); checkpoint; -- update a tuple from the first page, new tuple goes to last page update foo set i = 10000 where i = 1; -- delete everything on pages > 1 delete from foo where i > 10; -- truncate the table, including the page the updated tuple went to vacuum verbose foo; pg_ctl stop -m immediate This bug was introduced by commit 8805ff6580621d0daee350826de5211d6bb36ec3, in 9.2.2 (and 9.1.7 and 9.0.11), which fixed multiple WAL replay issues with Hot Standby. Before that commit, replaying a heap update didn't try to keep both buffers locked at the same time, which is necessary for the correctness of hot standby. The patch fixed that, but missed releasing the old buffer in this corner case. I was not able to come up with a scenario with full_page_writes=on where this would fail, but I'm also not 100% sure it can't happen. I scanned through the commit, and couldn't see any other instances of this kind of a bug. heap_xlog_update is more complicated than other redo functions, with all the return statements inside it. It could use some refactoring, but for now, I'll commit the attached small fix. - Heikki --------------070403020404030207080101 Content-Type: text/x-diff; name="fix-heap-update-redo-buffer-leak.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-heap-update-redo-buffer-leak.patch" diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 595dead..860fd20 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -5367,7 +5367,11 @@ newt:; ItemPointerGetBlockNumber(&(xlrec->newtid)), false); if (!BufferIsValid(nbuffer)) + { + if (BufferIsValid(obuffer)) + UnlockReleaseBuffer(obuffer); return; + } page = (Page) BufferGetPage(nbuffer); if (XLByteLE(lsn, PageGetLSN(page))) /* changes are applied */ --------------070403020404030207080101 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------070403020404030207080101--