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 1oNjwx-0003ie-Fl for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Aug 2022 23:56:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oNjww-00069g-3W for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Aug 2022 23:56:50 +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 1oNjwv-00069X-RQ for pgsql-bugs@lists.postgresql.org; Mon, 15 Aug 2022 23:56:49 +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 1oNjwt-0002O3-Jq for pgsql-bugs@lists.postgresql.org; Mon, 15 Aug 2022 23:56:49 +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 27FNuekq996032; Mon, 15 Aug 2022 19:56:40 -0400 From: Tom Lane To: Andres Freund cc: sk@zsrv.org, pgsql-bugs@lists.postgresql.org, Michael Paquier , Melanie Plageman Subject: Re: BUG #17568: unexpected zero page at block 0 during REINDEX CONCURRENTLY In-reply-to: <20220815233924.5jlus3ukkqmmts5g@awork3.anarazel.de> References: <17568-ef121b956ec1559c@postgresql.org> <20220815233924.5jlus3ukkqmmts5g@awork3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Mon, 15 Aug 2022 16:39:24 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <996030.1660607800.1@sss.pgh.pa.us> Date: Mon, 15 Aug 2022 19:56:40 -0400 Message-ID: <996031.1660607800@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > The easiest fix is likely to force all buffers to be forgotten at the end of > index_concurrently_build() or such. Race conditions there ... > I don't immediately see a nicer way to fix > this, we can't just lock the new index relation exclusively. Why not? If the index isn't valid yet, other backends have zero business touching it. I'd think about taking an exclusive lock to start with, and releasing it (downgrading to a non-exclusive lock) once the index is valid enough that other backends can access it, which would be just before we set pg_index.indisready to true. Basically, this is to enforce the previously-implicit contract that other sessions won't touch the index too soon against careless superusers. regards, tom lane