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 1x0rvj-004rBx-0m for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 02:39:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x0rvh-00F8hx-2h for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 02:39:25 +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 1x0rvh-00F8hi-1J for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 02:39:25 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x0rvf-00000003ESF-1t19 for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 02:39:24 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-482e2904915so1984781f8f.0 for ; Sun, 30 Aug 2026 19:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788143962; x=1788748762; darn=lists.postgresql.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Zf3wq6G3yKivwki8DymlL13zdGduYc5nagPfeKr6RVI=; b=dI/bwjQZrhN7L0BYEjSMCdA3ORsbF+DmQcn/w/AB8+vCUEG7UwqqHCedCGNJPZsmdC YtyzlQOj3Ugk+kGfTwUu0uGURPzb1Bsq8ooh89Qfj5gPBfOP/yJK8voU2guC4vH8M26k Y7A7WlzNKRBaQ1Ln3nQFYXaGIMG2axC/qnY/drx7tQ5svxEnArh5K0XY1RCqrlv9w11j 4oLhu6uVA/GGBp3wG/kHfj5e0EJpeT7QTd5/24GuPaMvfBfu5HakE8k9k7G05ELa7Srb Mpy5UNujGZM4cASqiRMoC62pzOUug6oTtzs1oOfcw927wRrk8lkMm2gymkFbBgjeYSTl hTPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788143962; x=1788748762; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Zf3wq6G3yKivwki8DymlL13zdGduYc5nagPfeKr6RVI=; b=GUSFS2CeLLSyxqW9LPLFYIMcUtzsohvvA/R2rHdk/HyyvRKvh79NIQheFuENyrDpq3 qOib0svPpN7W2NUWEaWi7zgyvZZFZ1+sop1LncmX+usho1PlGFvEFb/3kdLf31kwXQkA vTJICgLsPNm7FBcO4rLe0YvJeLCqM078fLP4Y92bPTCy+udDFEFFlzn+7Iu8Ci91b3SD F/K9irwotteScd9ivZNi3LoOclBInF2UIUW2fByOtcM1JjN8VMECNDM3lru0cCHxB/LC UGrc+MUykORKQBPEOBO5n4mWohbdhPoW6ez1Eua4rVe9i7/j/acsdGq07lwNdaEdd7Od 9gHw== X-Gm-Message-State: AFuF++mxqtpf0zdaqU8BMjsTiITSq9d4WxJwtQRntfCRGLIluxwmNgSD eJ11GY320j6qxrvqxivCtET07DVTU48poXWEF+CLSx59gS7Yc7cpy/j00MGsiw== X-Gm-Gg: AR+sD11Jv9WdCjOJ7em+uNm41toYl7uhONsL6vNDLqSVpDd7pco4pFipfhcIcglrlKg d8p2qIGftTlEfI4vyu5pkKP6nQWk87h97XPqyWZw/e90hgLdMn8Jb9XRiypxIXYfpARTYRD4n7W dmkTOexcuJ4nBVShpI+PMkpCtC12GG8MkV/rM2rkKNkw1kl3ANP7wKJi81iOjmndUgWDf8IGWWL DgLzJCG6JeQj6Mjjo/DdPSRmRe+jAT7HLY9C8118ZUwF6aS4vg5VkLLumwlQs7j6LDt1QdUdgAl fU4/n6uAkcXnSXb3pFVAsHKzx7De8LOvBBX5u5rSu8EItnK0RDq7bYmz0GFfObBRVBMrHAhoWDV dwb91cyHUvjL5cjMu1CH8SxVLR4TlIgL/YLIOtQEvKnpVYkAkT7/l9TYZjccDZEEffNFgLyZTU1 SkWV43ZtcfWBp6WMtEjQopu6N5MuyU9qkDxuxLXyatjI0ig92QDGR61S19zTnChTexh8XmHlBZY ibmgjTXAoDD3oMixfKvBUbh3TLQIqf1xW1Nv6zvij0nFasR3A== X-Received: by 2002:a05:600c:1d8c:b0:49b:916f:1471 with SMTP id 5b1f17b1804b1-49b91c1df21mr383783935e9.3.1788143961789; Sun, 30 Aug 2026 19:39:21 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49b9267c369sm172936065e9.3.2026.08.30.19.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2026 19:39:21 -0700 (PDT) Date: Mon, 31 Aug 2026 02:39:19 +0000 From: Bertrand Drouvot To: pgsql-hackers@lists.postgresql.org Cc: Amit Kapila Subject: Report relation extension blockers within parallel lock groups Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DQnhTvUE7k3IbPB4" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --DQnhTvUE7k3IbPB4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi hackers, While working on providing more informations related to locks (patch not shared yet), it appeared that pg_blocking_pids() can omit the process that is actually blocking a relation extension request. Indeed, commit 85f6b49c2c53 made relation extension locks conflict between members of the same parallel lock group, but did not update the same group filtering in pg_blocking_pids(). The attached adds the relation extension exception in pg_blocking_pids(). pg_blocking_pids() reports parallel workers using their lock group leader PID. Therefore, when one member of a parallel lock group blocks another, the PID supplied to pg_blocking_pids() can appear in the result. This does not mean that a process blocks itself. Rather, a lock held by one member of its parallel lock group blocks a lock request made by another member of that group. The patch documents this behavior. No regression test is added because ensuring relation extension lock contention between members of the same parallel lock group would be more complicated than needed for this simple patch. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --DQnhTvUE7k3IbPB4 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Report-relation-extension-blockers-within-paralle.patch" From a174547809a351d40bd48b226dd6bd8ec716083d Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot Date: Sat, 29 Aug 2026 04:24:42 +0000 Subject: [PATCH v1] Report relation extension blockers within parallel lock groups in pg_blocking_pids() Commit 85f6b49c2c53 made relation extension locks conflict between members of the same parallel lock group, but did not update the same group filtering in pg_blocking_pids(). So, pg_blocking_pids() can omit the process that is actually blocking a relation extension request. Add the relation extension exception in pg_blocking_pids(). pg_blocking_pids() reports parallel workers using their lock group leader PID. Therefore, when one member of a parallel lock group blocks another, the PID supplied to pg_blocking_pids() can appear in the result. This does not mean that a process blocks itself. Rather, a lock held by one member of its parallel lock group blocks a lock request made by another member of that group. The commit also documents this behavior. Author: Bertrand Drouvot Reviewed-by: Discussion: https://postgr.es/m/... --- doc/src/sgml/func/func-info.sgml | 14 +++++++++++--- src/backend/utils/adt/lockfuncs.c | 10 ++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) 68.7% doc/src/sgml/func/ 31.2% src/backend/utils/adt/ diff --git a/doc/src/sgml/func/func-info.sgml b/doc/src/sgml/func/func-info.sgml index 2f03766b67a..226a815916d 100644 --- a/doc/src/sgml/func/func-info.sgml +++ b/doc/src/sgml/func/func-info.sgml @@ -246,9 +246,17 @@ request and is ahead of it in the wait queue (soft block). When using parallel queries the result always lists client-visible process IDs (that is, pg_backend_pid results) even if the - actual lock is held or awaited by a child worker process. As a result - of that, there may be duplicated PIDs in the result. Also note that - when a prepared transaction holds a conflicting lock, it will be + actual lock is held or awaited by a child worker process. As a result + of that, there may be duplicated PIDs in the result. When members of + the same parallel lock group block each other on a relation extension + lock (shown as lock type extend in pg_locks), the + specified process ID can also appear in the result. This does not mean + that a process blocks itself. Rather, a lock held by one member of its + parallel lock group blocks a lock request made by another member of that + group. + Also note that when a prepared transaction holds a conflicting lock, + it will be represented by a zero process ID. diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index 3eb9a5b4215..1f0cc2b9bcb 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -518,8 +518,14 @@ pg_blocking_pids(PG_FUNCTION_ARGS) /* A proc never blocks itself, so ignore that entry */ if (instance == blocked_instance) continue; - /* Members of same lock group never block each other, either */ - if (instance->leaderPid == blocked_instance->leaderPid) + + /* + * Members of the same lock group do not block each other, except + * when extending a relation. + */ + if (instance->leaderPid == blocked_instance->leaderPid && + blocked_instance->locktag.locktag_type != + LOCKTAG_RELATION_EXTEND) continue; if (conflictMask & instance->holdMask) -- 2.34.1 --DQnhTvUE7k3IbPB4--