Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vZLWp-008szX-1Q for pgsql-general@arkaria.postgresql.org; Sat, 27 Dec 2025 04:03:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vZLWm-00B8fn-0g for pgsql-general@arkaria.postgresql.org; Sat, 27 Dec 2025 04:03:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vZLWl-00B8fe-2n for pgsql-general@lists.postgresql.org; Sat, 27 Dec 2025 04:03:40 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vZLWh-002oNk-2Z for pgsql-general@postgresql.org; Sat, 27 Dec 2025 04:03:39 +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 5BR43RlK1630378; Fri, 26 Dec 2025 23:03:27 -0500 From: Tom Lane To: Ian Dick cc: pgsql-general@postgresql.org Subject: Re: Some questions about CREATE INDEX CONCURRENTLY and pg_advisory_lock In-reply-to: References: Comments: In-reply-to Ian Dick message dated "Wed, 24 Dec 2025 22:26:26 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1630376.1766808207.1@sss.pgh.pa.us> Date: Fri, 26 Dec 2025 23:03:27 -0500 Message-ID: <1630377.1766808207@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ian Dick writes: > I recently noticed some behaviour regarding the CREATE INDEX CONCURRENTLY > operation, combined with pg_advisory_lock, which I found surprising. I've > looked online for a specific explanation of what's happening, but couldn't > seem to find a concrete explanation for what I'm seeing. You did find the explanation: > the 2nd phase of the index creation needs to wait until all current > transaction with a snapshot preceding index creation have finished: > "After the second scan, the index build must wait for any transactions that > have a snapshot (see Chapter 13 > ) predating the second > scan to terminate" The blocked "SELECT pg_advisory_lock" doesn't hold any interesting locks, but nonetheless it has a snapshot. > I'm also curious if it might be possible to patch the code to > ignore txns like this which should not interfere with the index creation. Doubt it. You may know that the blocked transaction will not later try to touch the table being indexed, but Postgres can't really know that, especially not from within a different session. regards, tom lane