Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVdeK-0003dZ-Ri for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Apr 2021 17:13:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lVdeJ-0006H2-Jk for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Apr 2021 17:13:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVdeJ-0006Gu-DJ for pgsql-hackers@lists.postgresql.org; Sun, 11 Apr 2021 17:13:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVdeC-0002fH-CQ for pgsql-hackers@lists.postgresql.org; Sun, 11 Apr 2021 17:13:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 13BHDENY2689874; Sun, 11 Apr 2021 13:13:15 -0400 From: Tom Lane To: Peter Geoghegan cc: Andres Freund , PostgreSQL Hackers Subject: Re: PANIC: wrong buffer passed to visibilitymap_clear In-reply-to: References: <2247102.1618008027@sss.pgh.pa.us> <20210409232739.sazp5p4xnnagrusa@alap3.anarazel.de> <20210409233203.3khg3s5iw34g4xrc@alap3.anarazel.de> <2644575.1618117467@sss.pgh.pa.us> <2679216.1618156670@sss.pgh.pa.us> Comments: In-reply-to Peter Geoghegan message dated "Sun, 11 Apr 2021 09:43:15 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2689872.1618161194.1@sss.pgh.pa.us> Date: Sun, 11 Apr 2021 13:13:14 -0400 Message-ID: <2689873.1618161194@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Geoghegan writes: > This isn't just any super-exclusive lock, either -- we were calling > ConditionalLockBufferForCleanup() at this point. > I now think that there is a good chance that we are seeing these > symptoms because the "conditional-ness" went away -- we accidentally > relied on that. Ah, I see it. In the fragment of heap_update where we have to do some TOAST work (starting at line 3815) we transiently *release our lock* on the old tuple's page. Unlike the earlier fragments that did that, this code path has no provision for rechecking whether the page has become all-visible, so if that does happen while we're without the lock then we lose. (It does look like RelationGetBufferForTuple knows about updating vmbuffer, but there's one code path through the if-nest at 3850ff that doesn't call that.) So the previous coding in vacuumlazy didn't tickle this because it would only set the all-visible bit on a page it had superexclusive lock on; that is, continuing to hold the pin was sufficient. Nonetheless, if four out of five paths through heap_update take care of this matter, I'd say it's heap_update's bug not vacuumlazy's bug that the fifth path doesn't. regards, tom lane