Re: Adding locks statistics
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, Jeff Davis <pgsql@j-davis.com>, Greg Sabino Mullane <htamfids@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2026-03-19T07:01:39Z
Lists: pgsql-hackers
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)). > + <structfield>waits</structfield> <type>bigint</type> > + </para> > + <para> > + Number of times a lock of this type had to wait because of a > + conflicting lock. Only incremented when <xref linkend="guc-log-lock-waits"/> > + is enabled and the lock was successfully acquired after waiting longer > + than <xref linkend="guc-deadlock-timeout"/>. > + </para> > + </entry> 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? + * Copyright (c) 2021-2025, PostgreSQL Global Development Group Incorrect date at the top of pgstat_lock.c. 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. It would be nice to document at the top of the new spec file what this test is here for, and perhaps name it stats-lock instead? -- Michael
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix injection point detach timing problem in TAP test for lock stats
- 3284e3f63cf0 19 (unreleased) landed
-
Use single LWLock for lock statistics in pgstats
- 404a17c155ac 19 (unreleased) landed
-
Add tests for lock statistics, take two
- 557a9f1e3e62 19 (unreleased) landed
-
Remove isolation test lock-stats
- 7c64d56fd976 19 (unreleased) landed
-
Avoid including clog.h in proc.h
- f227b7b20c36 19 (unreleased) landed
-
Don't include storage/lock.h in so many headers
- 2102ebb1953f 19 (unreleased) landed
-
Add support for lock statistics in pgstats
- 4019f725f5d4 19 (unreleased) landed
-
Move some code blocks in lock.c and proc.c
- a90d86518243 19 (unreleased) landed
-
Move declarations related to locktags from lock.h to new locktag.h
- 322bab79744d 19 (unreleased) landed