Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V5Nfd-0000dG-Kx for pgsql-bugs@arkaria.postgresql.org; Fri, 02 Aug 2013 22:18:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V5Nfd-0006VP-32 for pgsql-bugs@arkaria.postgresql.org; Fri, 02 Aug 2013 22:18:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V5Nfc-0006VE-1N; Fri, 02 Aug 2013 22:18:00 +0000 Received: from smtprelay0150.b.hostedemail.com ([64.98.42.150] helo=smtprelay.b.hostedemail.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V5NfT-00028o-9I; Fri, 02 Aug 2013 22:17:59 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay02.b.hostedemail.com (Postfix) with ESMTP id A4EBAD3865; Fri, 2 Aug 2013 22:17:49 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Panda: scanned! X-Spam-Summary: 50, 0, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::::::, RULES_HIT:355:379:599:871:967:973:988:989:1260:1311:1312:1313:1314:1345:1359:1437:1515:1516:1518:1519:1535:1539:1575:1594:1595:1596:1711:1730:1747:1764:1777:1792:2393:2525:2560:2563:2682:2685:2859:2915:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3867:3868:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4250:4605:4659:5007:6119:6261:6748:7281:9025:9121:10004:10400:10848:11232:11256:11257:11604:11658:11914:12517:12519:12660:13894:13895, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:0:0 X-HE-Tag: step35_7e31553bb111d X-Filterd-Recvd-Size: 6170 Received: from eldon.alvh.no-ip.org (unknown [181.226.153.169]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf02.b.hostedemail.com (Postfix) with ESMTPA; Fri, 2 Aug 2013 22:17:47 +0000 (UTC) Received: by eldon.alvh.no-ip.org (Postfix, from userid 1000) id F35C11FC5; Fri, 2 Aug 2013 18:17:43 -0400 (CLT) Date: Fri, 2 Aug 2013 18:17:43 -0400 From: Alvaro Herrera To: Jesse Denardo Cc: Bruce Momjian , pgsql-bugs@postgresql.org, Pg Hackers Subject: Re: 9.3beta2: Failure to pg_upgrade Message-ID: <20130802221743.GW5669@eldon.alvh.no-ip.org> References: <20130731160307.GC3716@momjian.us> <20130731165633.GW14652@eldon.alvh.no-ip.org> <20130731170631.GG3716@momjian.us> <20130731205532.GA14652@eldon.alvh.no-ip.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="69pVuxX8awAiJ7fD" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20130731205532.GA14652@eldon.alvh.no-ip.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) 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 --69pVuxX8awAiJ7fD Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Alvaro Herrera escribió: > As it turns out, I have a patched slru.c that adds a new function to > verify whether a page exists on disk. I created this for the commit > timestamp module, for the BDR branch, but I think it's what we need > here. Here's a patch that should fix the problem. Jesse, if you're able to test it, please give it a run and let me know if it works for you. I was able to upgrade an installation containing a problem that should reproduce yours. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --69pVuxX8awAiJ7fD Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="extend-slru.patch" *** a/src/backend/access/transam/multixact.c --- b/src/backend/access/transam/multixact.c *************** *** 1719,1724 **** ZeroMultiXactMemberPage(int pageno, bool writeXlog) --- 1719,1756 ---- } /* + * After a binary upgrade from <= 9.2, the pg_multixact/offset SLRU area might + * contain files that are shorter than necessary; this would occur if the old + * installation had used multixacts beyond the first page (files cannot be + * copied, because the on-disk representation is different). pg_upgrade would + * update pg_control to set the next offset value to be at that position, so + * that tuples marked as locked by such MultiXacts would be seen as visible + * without having to consult multixact. However, trying to create a use a new + * MultiXactId would result in an error because the page on which the new value + * would reside does not exist. This routine is in charge of creating such + * pages. + */ + static void + MaybeExtendOffsetSlru(void) + { + int pageno; + + pageno = MultiXactIdToOffsetPage(MultiXactState->nextMXact); + + LWLockAcquire(MultiXactOffsetControlLock, LW_EXCLUSIVE); + + if (!SimpleLruDoesPhysicalPageExist(MultiXactOffsetCtl, pageno)) + { + int slotno; + + slotno = ZeroMultiXactOffsetPage(pageno, false); + SimpleLruWritePage(MultiXactOffsetCtl, slotno); + } + + LWLockRelease(MultiXactOffsetControlLock); + } + + /* * This must be called ONCE during postmaster or standalone-backend startup. * * StartupXLOG has already established nextMXact/nextOffset by calling *************** *** 1738,1743 **** StartupMultiXact(void) --- 1770,1782 ---- int entryno; int flagsoff; + /* + * During a binary upgrade, make sure that the offsets SLRU is large + * enough to contain the next value that would be created. + */ + if (IsBinaryUpgrade) + MaybeExtendOffsetSlru(); + /* Clean up offsets state */ LWLockAcquire(MultiXactOffsetControlLock, LW_EXCLUSIVE); *** a/src/backend/access/transam/slru.c --- b/src/backend/access/transam/slru.c *************** *** 563,568 **** SimpleLruWritePage(SlruCtl ctl, int slotno) --- 563,612 ---- SlruInternalWritePage(ctl, slotno, NULL); } + /* + * Return whether the given page exists on disk. + * + * A false return means that either the file does not exist, or that it's not + * large enough to contain the given page. + */ + bool + SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno) + { + int segno = pageno / SLRU_PAGES_PER_SEGMENT; + int rpageno = pageno % SLRU_PAGES_PER_SEGMENT; + int offset = rpageno * BLCKSZ; + char path[MAXPGPATH]; + int fd; + bool result; + off_t endpos; + + SlruFileName(ctl, path, segno); + + fd = OpenTransientFile(path, O_RDWR | PG_BINARY, S_IRUSR | S_IWUSR); + if (fd < 0) + { + /* expected: file doesn't exist */ + if (errno == ENOENT) + return false; + + /* report error normally */ + slru_errcause = SLRU_OPEN_FAILED; + slru_errno = errno; + SlruReportIOError(ctl, pageno, 0); + } + + if ((endpos = lseek(fd, 0, SEEK_END)) < 0) + { + slru_errcause = SLRU_OPEN_FAILED; + slru_errno = errno; + SlruReportIOError(ctl, pageno, 0); + } + + result = endpos >= (off_t) (offset + BLCKSZ); + + CloseTransientFile(fd); + return result; + } /* * Physical read of a (previously existing) page into a buffer slot *** a/src/include/access/slru.h --- b/src/include/access/slru.h *************** *** 145,150 **** extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, --- 145,151 ---- extern void SimpleLruWritePage(SlruCtl ctl, int slotno); extern void SimpleLruFlush(SlruCtl ctl, bool checkpoint); extern void SimpleLruTruncate(SlruCtl ctl, int cutoffPage); + extern bool SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno); typedef bool (*SlruScanCallback) (SlruCtl ctl, char *filename, int segpage, void *data); --69pVuxX8awAiJ7fD 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 --69pVuxX8awAiJ7fD--