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 1wcPrw-003KhD-16 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jun 2026 15:50:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcPru-001ZjZ-0B for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Jun 2026 15:50:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcPrt-001ZjR-2T for pgsql-hackers@lists.postgresql.org; Wed, 24 Jun 2026 15:50:25 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wcPrr-000000003Bz-0gTE for pgsql-hackers@lists.postgresql.org; Wed, 24 Jun 2026 15:50:25 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-462342ac290so1550770f8f.2 for ; Wed, 24 Jun 2026 08:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782316222; x=1782921022; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zrC1yI09lcrDak1TkiaQSnEvpCF65wpTw8vy3JKWupg=; b=JfjuyXV/WneDEUprB5/mbAgGu5Cav+ZNX2k9QqGt31Pt5WyvowXn5zVd813NKoitAF 6TqOZZNeZIt2ztMp5iYiSb20UiCtEcvivLiTimQPercLJBCU7yd3THsZJKWhwByeobWl m9ZdlDV3wtefeVtO+S2SnSVJs/dGfDDfP2PNOQ9RlC1pqMVmvoRkRjzdz7IBqeN+/49K Z0Hh8U+V+rvdKRHsmSxBrUgzV/ty6Dh1L99YggWeHEZEQw9zrSO7QAPa1CQ5TLIL6R9f 7ZmYbDhEw5HYsseK8IrywosF3/u/mnvO+KUD8MhownP/Xt5alXc9FdU0cr/lqNAcGmFL NNeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782316222; x=1782921022; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zrC1yI09lcrDak1TkiaQSnEvpCF65wpTw8vy3JKWupg=; b=svL/kbBM0rjNG4/RuVxFbu7CKby1GUaBOcK1lDL3mzQ7iBCvFr0D+FM19NpyoJC5rz RfPOglndB7Jq93NgY3Du7QQY4cNHiaMR2CGr/lNXl7OjRys357+Ne5hWeVa7nhlv0afg 4a7H4QpNy0IOHQpfD1eeB8POFurgIFg0F3SUrHlCPN1ykXL6rFX75vs3L6b9SkAWg7jy jUlKo2P5Sc5clV5731brrOwPr/4zf6E2kSM7SDa+zexHHWmoUTZXi+P6NdQU1lSItaqX aNhz+1VqmtWwsOa83bZu3ui5pQL1F6QvDbajnAU2KN/8+ZkhmEKdSiMqnMj58aa9v3DT nRtQ== X-Forwarded-Encrypted: i=1; AHgh+RoqFtXseaWhoABhYw94FTF5oTVERpzps12FDWebD+cb5MtPDJfN/xllktqn5DaUQ0TeYaQfogc/2y6AvRqb@lists.postgresql.org X-Gm-Message-State: AOJu0YzEqs59MAisdBAmPEAjyP4n1SwGkLkRZPeiKQFvwjRoDEAllOZ0 8CAjwv79kluyXVbU5kAa/J4z2GFJkGYsZSOSqdLGOHiFs/F7G2eRg3Cr X-Gm-Gg: AfdE7clMdMee7NOBfqONc5SIZYpOXj2IBMwLeOTTofz3Su0z0bHHcpxbLJxganSxWtF 55QlZhUMApi/mbQG/fZEgdP01fjeenmaHLfcj70OZPOQIz1aeXVpCAiF23at15v5eMnXA6qgWmT RkxWcht2PR9M7HcRZ+kQK83PNcQQdxQMW5a78B7TWZdkno/9YAqr4Jrt+dLtHoF/Icnt/S+0ZPT H7O/O3exhXLOjn5h8cdoVWazZQ6Mz/4QHRhQNCnZzUjSW3sNV8WPCUYhb4cYMnmBcCvuzSlWKau 1ez/73lIgZ87vaMB2SmbTAWe+PYpiFnhpeesKUuzi/nDMROFTvWKvqBhTMo70IPprVrN+BU4Rin JUqumEG0WY59uKSNDPadTt/IBq8vPOXo3LAtrMEIAJCSmk6oQQK9J1ZH7G1gt5uSfYtBJmf1IlM Q1iQ641CWENssQuM/jzalC2BiEVrekp42j8QpysJInf0o7Vi/HdXKqWMcTKuLu25EefVOIooJJ X-Received: by 2002:a05:6000:288c:b0:462:93cf:d510 with SMTP id ffacd0b85a97d-46ad90f5d88mr12437353f8f.12.1782316221716; Wed, 24 Jun 2026 08:50: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 ffacd0b85a97d-46c9f240c3dsm5279973f8f.35.2026.06.24.08.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 08:50:21 -0700 (PDT) Date: Wed, 24 Jun 2026 15:50:19 +0000 From: Bertrand Drouvot To: Tatsuya Kawata Cc: Michael Paquier , pgsql-hackers@lists.postgresql.org Subject: Re: Add per-backend lock statistics Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Kawata-san, On Wed, Jun 24, 2026 at 10:49:44PM +0900, Tatsuya Kawata wrote: > Hi Bertrand-san, > > I tested the patch locally and did not find any functional issue. Thanks! > I have two suggestions below. > > == Doc suggestion == > > When the workload uses parallel scans, pg_stat_lock.fastpath_exceeded > grows more than what pg_stat_get_backend_lock shows for any > individual pid. The gap is the parallel workers' contribution: > each worker locks the valid subplans independently, accumulates into > its own per-backend entry, and the entry is dropped at worker exit > -- so the contribution is not folded into the leader's per-backend > view. > > This is a property of the per-backend stats infrastructure rather > than something this patch introduces, but since one of the stated > motivations is "Isolate problematic sessions", users may > intuitively expect parallel-worker contributions to be visible > under the leader's pid. A short note in the docs of the per-backend > functions clarifying that > parallel-worker contributions are not aggregated into the leader's > entry would help avoid that misunderstanding. That's right, and the same could be said for per-backend I/O and WAL stats. The stats are flushed when the transaction finish and then are visible from that moment. The stats are gone once the backend exit. For parallel workers this window is very short (between the flush and the exit) so that we can say that their stats are not visible in practice. I think that flushing statistics within running transactions [1] could help to see what's going on for parallel workers too. That said, I'm not sure the doc needs any clarifications given that those functions take a PID as parameter and that they state something like "Returns I/O /WAL statistics about the backend with the specified process ID". > == Column suggestion for pg_stat_lock == > > pg_stat_io has a backend_type column, which lets users still see > parallel-worker contributions in aggregate (via WHERE > backend_type='background worker') after workers exit. pg_stat_lock > has only locktype, so worker contributions blend into the relation > row and cannot be separated even in aggregate. > > This may be out of scope for the present patch, but I wonder if > adding a backend_type axis to pg_stat_lock could be considered in a > follow-up patch. It would give an alternative attribution path > (similar to pg_stat_io's backend_type column) when per-backend > statistics cannot help. It's not related to this thread so that might be worth a dedicated one but I'm not sure that would be more actionable while consuming more resources. [1]: https://postgr.es/m/CAA5RZ0uA-4qcD3%2B2hjcE_-zQUBhvWf5foPM2vzYneFKrJLsBDQ%40mail.gmail.com Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com