Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WxOho-0004zN-1Q for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Jun 2014 22:51:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WxOhn-0003O6-9d for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Jun 2014 22:51:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WxOhk-0003Nv-Um for pgsql-bugs@postgresql.org; Wed, 18 Jun 2014 22:51:45 +0000 Received: from smtprelay0059.b.hostedemail.com ([64.98.42.59] helo=smtprelay.b.hostedemail.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WxOhc-0006Kd-B3 for pgsql-bugs@postgresql.org; Wed, 18 Jun 2014 22:51:42 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay02.b.hostedemail.com (Postfix) with ESMTP id D7901D3817; Wed, 18 Jun 2014 22:51:34 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Spam-Summary: 50, 0, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::::, RULES_HIT:41:355:379:599:871:960:966:967:968:973:988:989:1260:1311:1312:1313:1314:1345:1359:1437:1515:1516:1518:1519:1535:1542:1575:1594:1595:1596:1711:1730:1747:1764:1777:1792:2196:2199:2393:2525:2553:2560:2563:2682:2685:2693:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3355:3834:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4184:4385:4605:4659:5007:6119:6261:6748:7281:7903:8957:9025:9121:10004:10394:10400:10450:10455:10848:11232:11256:11257:11604:11658:11914:12296:12517:12519:12660:12679:12740:13161:13184:13229:13894:13895:19904:19999:21060:21067, 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: bean41_821bed78d363f X-Filterd-Recvd-Size: 5757 Received: from eldon.alvh.no-ip.org (pc-65-79-161-190.cm.vtr.net [190.161.79.65]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf10.b.hostedemail.com (Postfix) with ESMTPA; Wed, 18 Jun 2014 22:51:34 +0000 (UTC) Received: by eldon.alvh.no-ip.org (Postfix, from userid 1000) id 3C29F1FCB; Wed, 18 Jun 2014 18:51:32 -0400 (CLT) Date: Wed, 18 Jun 2014 18:51:31 -0400 From: Alvaro Herrera To: Bruce Momjian Cc: Andres Freund , PostgreSQL Bugs Subject: Re: pg_upgrade < 9.3 -> >=9.3 misses a step around multixacts Message-ID: <20140618225131.GN18688@eldon.alvh.no-ip.org> References: <20140530121631.GE25431@alap3.anarazel.de> <20140530132916.GM28490@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="eMnpOGXCMazMAbfp" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20140530132916.GM28490@momjian.us> 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 --eMnpOGXCMazMAbfp Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Bruce Momjian wrote: > On Fri, May 30, 2014 at 02:16:31PM +0200, Andres Freund wrote: > > Hi, > > > > When upgrading a < 9.3 cluster pg_upgrade doesn't bother to keep the old > > multixacts around because they won't be read after the upgrade (and > > aren't compatible). It just resets the new cluster's nextMulti to the > > old + 1. > > Unfortunately that means that there'll be a offsets/0000 file created by > > initdb around. Sounds harmless enough, but that'll actually cause > > problems if the old cluster had a nextMulti that's bigger than that > > page. I've been playing with this a bit. Here's a patch that just does rmtree() of the problematic file during pg_upgrade, as proposed by Andres, which solves the problem. Note that this patch removes the 0000 file in both cases: when upgrading from 9.2, and when upgrading from 9.3+. The former case is the bug that Andres reported. In the second case, we overwrite the files with the ones from the old cluster; if there's a lingering 0000 file in the new cluster, it would cause problems as well. (Really, I don't see any reason to think that these two cases are any different.) > This is a bug in 9.3 pg_upgrade as well? Why has no one reported it > before? I think one reason is that not all upgrades see an issue here; for old clusters that haven't gone beyond the 0000 offset file, there is no problem. For clusters that have gone beyond 0000 but not by much, the file will be deleted during the first truncation. It only becomes a problem if the cluster is close enough to 2^31. Another thing to keep in consideration is that initdb initializes all databases' datminmxid to 1. If the old cluster was past the 2^31 point, it means the datminmxid doesn't move from 1 until the actual wraparound. I noticed another problem while trying to reproduce it. It only happens in assert-enabled builds: when FreezeMultiXactId() sees an old multi, it asserts that it mustn't be running anymore, which is fine except that if the multi value is one that survived a pg_upgrade cycle from 9.2 or older (i.e. it was a share-locked tuple in the old cluster), an error is raised when the assertion is checked. Since it doesn't make sense to examine its running status at that point, the attached patch simply disables the assertion in that case. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --eMnpOGXCMazMAbfp Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="multiupgrade.patch" diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c index cd70b6a..74e5b63 100644 --- a/contrib/pg_upgrade/pg_upgrade.c +++ b/contrib/pg_upgrade/pg_upgrade.c @@ -398,6 +398,8 @@ copy_subdir_files(char *subdir) static void copy_clog_xlog_xid(void) { + char multioffdir[MAXPGPATH]; + /* copy old commit logs to new data dir */ copy_subdir_files("pg_clog"); @@ -410,6 +412,16 @@ copy_clog_xlog_xid(void) check_ok(); /* + * Remove pg_multixact/offset files before going any further. initdb + * created file 0000 there, which is problematic for future multixact + * truncation. Note we remove any other junk in the subdir alongside the + * 0000 file. + */ + snprintf(multioffdir, sizeof(multioffdir), + "%s/pg_multixact/offsets", new_cluster.pgdata); + rmtree(multioffdir, false); + + /* * If the old server is before the MULTIXACT_FORMATCHANGE_CAT_VER change * (see pg_upgrade.h) and the new server is after, then we don't copy * pg_multixact files, but we need to reset pg_control so that the new diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index ccdcb5b..baed722 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -5326,8 +5326,14 @@ FreezeMultiXactId(MultiXactId multi, uint16 t_infomask, * was a locker only, it can be removed without any further * consideration; but if it contained an update, we might need to * preserve it. + * + * Don't assert MultiXactIdIsRunning if the multi came from a + * pg_upgrade'd share-locked tuple, though, as doing that causes an + * error to be raised unnecessarily. */ - Assert(!MultiXactIdIsRunning(multi)); + Assert((!(t_infomask & HEAP_LOCK_MASK) && + HEAP_XMAX_IS_LOCKED_ONLY(t_infomask)) || + !MultiXactIdIsRunning(multi)); if (HEAP_XMAX_IS_LOCKED_ONLY(t_infomask)) { *flags |= FRM_INVALIDATE_XMAX; --eMnpOGXCMazMAbfp 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 --eMnpOGXCMazMAbfp--