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 1vt8k7-0058cm-2W for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 18:27:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vt8k6-005Lsc-27 for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 18:27:14 +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 1vt8k6-005LsU-1B for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 18:27:14 +0000 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vt8k3-00000000BHm-26gD for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 18:27:14 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 3783AEC0295; Thu, 19 Feb 2026 13:27:11 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 19 Feb 2026 13:27:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1771525631; x=1771612031; bh=Zqp7s9P3PS sX8bvCOpqosr/ft6x8xjP78PCo06PNXuI=; b=KN7dyeOojteMyNG2B4KJ5FBkdS Tcbild6lA0NggIc5IT+2dfxXJwNsLm6uQXtluPIaXbaSXnvGssXXLIeuMcm5ZkoP AxC9CrrTgaPHpbO3CGn/hBE/skIrxJ6vGo4i50GRQIL9TZfeRB4LU/4FCdvW0zsW rX89bcjfWxGh/FvYYiK98qCP8ovrEr1Na5v4CTDfICVT1md41V9LDuqMcdK62KoW ICYSr2M3Y18IQkNJhpeYR8l7wNhZIY4FsJdWSgRZ8GVKQNhQC7i+TLMhA1xCRyQJ LKacuy+faDFyq9alPbK4CpC9SvaAuwv5eUz/V39IWS7mZKm8JjaQ8GWYQeJg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1771525631; x=1771612031; bh=Zqp7s9P3PSsX8bvCOpqosr/ft6x8xjP78PC o06PNXuI=; b=YmL/yNzxkarEMypLAQBkHzZtV9wEUW8gwTcMbVdA/5VpJye5swf SFEhIUvtD0QQKFP225q10XKJRLZXR0nxMQxwiSqcWvQxdVacD0cbQ/OhpK3RrJAA y1v/fpkyZE65zokI4Kd0XQEdcpKRkTmDjuKpTAKpGMLQYxkpcEyJ15sxRucGAhE1 JAK1POwl765dLI2VQbpA2MO6SIyKqmVbWCGJDiAJTzF0oce1D//Pyo02pWMnKruZ +NMFKImPaYK+8Vhz7YQVi7ua67kosx+QaDR5XBcXLsAGS9iMdBplZpQ+YurxsK0q yxpTK+o2FrwGAKyFQ+Yd+ataCnAN26b8CCQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvdeivdegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefh ueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeehpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegsvghrthhrrghnuggurhhouhhvohhtrdhpghesgh hmrghilhdrtghomhdprhgtphhtthhopehhthgrmhhfihgushesghhmrghilhdrtghomhdp rhgtphhtthhopehpghhsqhhlsehjqdgurghvihhsrdgtohhmpdhrtghpthhtohepphhgsh hqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghp thhtohepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 19 Feb 2026 13:27:10 -0500 (EST) Date: Thu, 19 Feb 2026 13:27:10 -0500 From: Andres Freund To: Michael Paquier Cc: Bertrand Drouvot , Jeff Davis , Greg Sabino Mullane , pgsql-hackers@lists.postgresql.org Subject: Re: Adding locks 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, On 2026-02-19 13:06:52 +0900, Michael Paquier wrote: > On Tue, Feb 17, 2026 at 04:33:54PM +0000, Bertrand Drouvot wrote: > > Okay, done that way in the attached. To avoid overhead due to timing as much as > > possible, the patch simply relies on log_lock_waits and deadlock_timeout. It means > > that it relies on the existing code, and increments waits and wait_time only if > > log_lock_waits is on and if the session waited longer than deadlock_timeout. > > > > I did not want to dissociate the waits and wait_time increments so that their > > ratio could still make sense. > > > > That sounds like a good compromise, thoughts? > > else if (myWaitStatus == PROC_WAIT_STATUS_OK) > + { > + /* Increment the lock statistics counters */ > + pgstat_count_lock_waits(locallock->tag.lock.locktag_type); > + pgstat_count_lock_wait_time(locallock->tag.lock.locktag_type, msecs); Why do two external function calls? The function calls are at least as expensive as the work inside them, so doing this separately adds a fair bit of overhead. > Not sure that it makes much sense to me to rely on log_lock_waits > being enabled to decide if this count and this time are aggregated. > The log information and the stats gathering are two separate things. > Wouldn't it make more sense to call pgstat_count_lock_waits() outside > of this code path, when we know myWaitStatus? IDK, it doesn't seem unreasonable to not duplicate work. If the delay is very short it's probably also not that interesting to track, but I guess that's debatable. > While relying on the time calculating for the logs data is a good > idea, it seems to me that we should have a separate GUC to enable this > number, like a new track_lock_timings? If track_lock_timings or > log_lock_waits is enabled, we should calculate the time difference. > All these decisions also depends on what deadlock_state holds on top > of myWaitStatus, I guess.. I don't think it's worth having a separate GUC to track this. The realistic number of calls in a certain timespan to this is way way lower than something like track_io_timing, track_wal_io_timing or such. So I don't think we need an opt-out here like for those. If we eventually can reduce the overhead of the other track_* GUCs, we should remove them too, but I think that's further out. Greetings, Andres Freund