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 1w3CRi-001068-1a for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2026 12:25:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w3CRg-000S2y-0Q for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2026 12:25:48 +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 1w3CRf-000S2o-2M for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2026 12:25:47 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w3CRc-000000018mO-2s04 for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2026 12:25:47 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-486b96760easo9876795e9.2 for ; Thu, 19 Mar 2026 05:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773923144; x=1774527944; 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=4xmh/rVE8RD8LWRDLndHrpQz9dd+sdxT0cUhCcAqkXk=; b=Mp78hIR6pfJn63EkDlvIcJtmeD95i6MpfkFBOhcs4USfEGW0n13LgE4v++w+IS6DIF EipRCyqzP5pfFPJs/KJpoNw8v6ZZLc32Xp+mwjqR9vSn1u9qvPUYwgVXNY7ottE2qNZx FS5Ipr+3qS+7RbMhR8Qe8dgWKApEzyRafqgRpo3oXjTro0BgGtAOG3ClispUXJwetDjl 1YSUZ1D/pcnSt/nwEq9XrfkmpMse5l0nx0ADb6gTx7eTVmjV+x0BQmusAFBQYuHqL+ic 2+PE2atQgVJUNb/iYEFUy8oFX6wlcVFtkLaxAoPZzki5HJLUNBTE2kG/qhhWzYfF8mIy rYSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773923144; x=1774527944; 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=4xmh/rVE8RD8LWRDLndHrpQz9dd+sdxT0cUhCcAqkXk=; b=nnlNnQPITpFm/kjvxrHlsj8pUTAlxgaOgx0W6ZhhYpz7Sejya/2p2LuLux4FX6QHB6 v/3kYsmElHioe16dUwTSW6c/in7n3bBbaNhCrMSLxZ5miEuwZeAjbkfWQMVltoszKd50 /Yq6uWiN4G7OY6AXXKmYlmJymNnzF+yzfTWNfD+1dJ18KUM7d49aMpKPGWLe7N87enO4 psAViP10ycWMwXGrRNB1cyAyF7WJUGwpgB417nc/zr0qL/1xW4acFJDETf0vkjZTEIQG 6eaznE891OpoyLuBuSFMTHe2feTY9U6vner0fXOOxh5G6p0E7c9jW7mECYdeE16TZVwb RyRA== X-Forwarded-Encrypted: i=1; AJvYcCWvVu01PfGzn7ehF9SmSeOBUA7z1jHS/0OeuSbCYM1hUHPJwnSKr8T+CYIdV37PqPOyfpPWYnTZ/J5v7DSo@lists.postgresql.org X-Gm-Message-State: AOJu0YzoZ8AMCSGU3qB3B/3UssyI7+MMt4OcrXO0DpjQSzKYvlPr0bV/ iEcpwGfYsHa12KtUez5le7XQmHen8AiiwLDHa+8UXRamJXGDjkCti+5S X-Gm-Gg: ATEYQzzUhfzs+r6CDcw4URsvm2Bn0gDwCzizuqw9y+tTFQQ82ZLpq4rHQIs4h5hibxH don7Zhd4GPL/8EFS9c8eSVgois/JmyjcsJpQooMvKpQTkQUxhOnKhvh8Doszztt83TnRIlF+P3M xwV7giPNVLemNGXLX+EgJWxXQ312FBnJX4ZeJMH0IKLbM/ZlsF/4Rr8GyD604fn6kQ6p9mZfPix wGgDebXInpgBbQfNQtIBqEIz/DnHnhCxjmeUcCivsY4bzfjE1+BmSBXk4deI2x9AQYvMR8nojP+ yLyUmkVd+qEz+Ukvb3EG62pDPYAKpmRO575sxQRURNrRH1oLOQNqSnjo/HsiDG4eMvMnJZcQ1Wc sdI6/7BAA7dzjA1+KDbp8FZ3xRkEF7tUQYDKpufmO5PX51P3vQQIxhHYvX3JGZ4/OJ28TeE7dBv zUz/etlU20Zs8XUlPKcKBh1rjxPZynXV18zP3q/hKgeFTxsDKDqT/J+S7unfzunF9PLZqse4YyA vMchER7AORKbXOWNBpLImX3u6AvKXGO1Ehjg9QTb2+6yEIih1aefOVxzw== X-Received: by 2002:a05:600c:8218:b0:47e:e57d:404 with SMTP id 5b1f17b1804b1-486f4475336mr131441455e9.16.1773923143213; Thu, 19 Mar 2026 05:25:43 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486fd9845a2sm17450795e9.6.2026.03.19.05.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 05:25:42 -0700 (PDT) Date: Thu, 19 Mar 2026 12:25:41 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Andres Freund , Jeff Davis , Greg Sabino Mullane , pgsql-hackers@lists.postgresql.org Subject: Re: Adding locks statistics Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="YVZ2rdHTqHRFZ4HX" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --YVZ2rdHTqHRFZ4HX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Thu, Mar 19, 2026 at 04:01:39PM +0900, Michael Paquier wrote: > On Wed, Mar 18, 2026 at 02:51:01PM +0000, Bertrand Drouvot wrote: > > This is done that way in the attached, so that we don't need the extra output in > > the _1.out file and the test time is reduced (since the deadlock timeout is set > > to 10ms in the test, I changed the sleep time to 50ms (I did not want to be very > > close to 10ms)). > > > + waits bigint > > + > > + > > + Number of times a lock of this type had to wait because of a > > + conflicting lock. Only incremented when > > + is enabled and the lock was successfully acquired after waiting longer > > + than . > > + > > + > > It does not make much sense to me to decide that the counter is > incremented if a GUC related to a control of the logs generated is > enabled. It's a fact that log_lock_waits is enabled by default these > days, hence we will be able to get the time calculation for free for > most deployments, but it seems inconsistent to me to not count this > information if the GUC is disabled. We should increment the counter > and aggregate the time spent on the wait all the time, no? Yeah that's another way to think about it. In my mind the GUC was a "protection" to be able to avoid the extra GetCurrentTimestamp() call. But since it's done only if we waited longer than the deadlock timeout that's also fine to call GetCurrentTimestamp() even if log_lock_waits is off. Done that way in the attached. > > + * Copyright (c) 2021-2025, PostgreSQL Global Development Group > > Incorrect date at the top of pgstat_lock.c. Yeah, so replaced 2025 with 2026. I did not change 2021 because it's mainly copied from pgstat_io.c and I also think that's not that important ([1]). > storage/lock.h is included in pgstat.h as LOCKTAG_LAST_TYPE is wanted > for the new lock stats structure. That would pull in a lot of header > data into pgstat.h. How about creating a new header that splits a > portion of lock.h into a new file? LockTagType, LOCKTAG_LAST_TYPE, > LockTagTypeNames at least and perhaps a few other things? Or we could > just limit ourselves to a locktag.h with these three, then include the > new locktag.h in pgstat.h. That's a good idea! I only moved LockTagType, LOCKTAG_LAST_TYPE, LockTagTypeNames and LOCKTAG into a new locktag.h. I chose not to move the SET_LOCKTAG_* macros because then we'd also need to move DEFAULT_LOCKMETHOD and USER_LOCKMETHOD that I think are better suited in lock.h. I did not check if there are any other files that could benefit of using locktag.h instead of lock.h but that's something I'll do and open a dedicated if any (once locktag.h is in the tree). > It would be nice to document at the top of the new spec file what this > test is here for, Yeah, I copied stats.spec which has no comments but better to add some. Done in the new version. > and perhaps name it stats-lock instead? Not sure as we already have multixact-stats. [1]: https://postgr.es/m/202501211750.xf5j6thdkppy%40alvherre.pgsql Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --YVZ2rdHTqHRFZ4HX Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v11-0001-Add-storage-locktag.h.patch"