Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aqa1U-0001fj-18 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2016 05:41:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aqa1T-0003cF-JD for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Apr 2016 05:40:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aqa08-0001k4-4L for pgsql-hackers@postgresql.org; Thu, 14 Apr 2016 05:39:36 +0000 Received: from raven.toroid.org ([178.63.84.200]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aqa05-0004sv-20 for pgsql-hackers@postgresql.org; Thu, 14 Apr 2016 05:39:35 +0000 Received: from kea.toroid.org (unknown [10.9.8.10]) by raven.toroid.org (Postfix) with ESMTP id 351AFE5000D; Thu, 14 Apr 2016 07:39:31 +0200 (CEST) Received: by kea.toroid.org (Postfix, from userid 1000) id C4EF24E1610; Thu, 14 Apr 2016 11:09:29 +0530 (IST) Date: Thu, 14 Apr 2016 11:09:29 +0530 From: Abhijit Menon-Sen To: Robert Haas Cc: Andres Freund , Michael Paquier , Haribabu Kommi , Thom Brown , Fabien COELHO , pgsql-hackers@postgresql.org Subject: Re: [BUGS] Breakage with VACUUM ANALYSE + partitions Message-ID: <20160414053929.GA29751@toroid.org> References: <20160326123942.qnuwqg3yg2y7ae4p@alap3.anarazel.de> <20160411165054.r35o4fjicdg4avs7@alap3.anarazel.de> <20160411171742.n5xebjt7tcdy4sxf@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org At 2016-04-12 09:00:57 -0400, robertmhaas@gmail.com wrote: > > On Mon, Apr 11, 2016 at 1:17 PM, Andres Freund wrote: > > > > 3) Actually handle the case of the last open segment not being > > RELSEG_SIZE properly in _mdfd_getseg() - mdnblocks() does so. > > #3 seems like it's probably about 15 years overdue, so let's do that > anyway. I don't have anything useful to contribute, I'm just trying to understand this fix. _mdfd_getseg() looks like this: targetseg = blkno / ((BlockNumber) RELSEG_SIZE); for (nextsegno = 1; nextsegno <= targetseg; nextsegno++) { Assert(nextsegno == v->mdfd_segno + 1); if (v->mdfd_chain == NULL) { /* * Normally we will create new segments only if authorized by the * caller (i.e., we are doing mdextend()). […] */ if (behavior == EXTENSION_CREATE || InRecovery) { if (_mdnblocks(reln, forknum, v) < RELSEG_SIZE) /* mdextend */ v->mdfd_chain = _mdfd_openseg(reln, forknum, +nextsegno, O_CREAT); } else { /* We won't create segment if not existent */ v->mdfd_chain = _mdfd_openseg(reln, forknum, nextsegno, 0); } if (v->mdfd_chain == NULL) /* return NULL or ERROR */ } v = v->mdfd_chain; } Do I understand correctly that the case of the "last open segment" (i.e., the one for which mdfd_chain == NULL) not being RELSEG_SIZE (i.e., _mdnblocks(reln, forknum, v) < RELSEG_SIZE) should not call _mfdf_openseg on nextsegno if behaviour is not EXTENSION_CREATE or InRecovery? And that "We won't create segment if not existent" should happen, but doesn't only because the next segment file wasn't removed earlier, so we have to add an extra check for that case? In other words, is something like the following what's needed here, or is there more to it? -- Abhijit diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 578276d..58ea5a0 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -1783,6 +1783,8 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, if (v->mdfd_chain == NULL) { + bool thisSegNeedsExtension = _mdnblocks(reln, forknum, v) < RELSEG_SIZE; + /* * Normally we will create new segments only if authorized by the * caller (i.e., we are doing mdextend()). But when doing WAL @@ -1799,7 +1801,7 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, */ if (behavior == EXTENSION_CREATE || InRecovery) { - if (_mdnblocks(reln, forknum, v) < RELSEG_SIZE) + if (thisSegNeedsExtension) { char *zerobuf = palloc0(BLCKSZ); @@ -1810,7 +1812,7 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, } v->mdfd_chain = _mdfd_openseg(reln, forknum, +nextsegno, O_CREAT); } - else + else if (!thisSegNeedsExtension) { /* We won't create segment if not existent */ v->mdfd_chain = _mdfd_openseg(reln, forknum, nextsegno, 0); -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers