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-24T07:02:55Z
Lists: pgsql-hackers
On Sat, Mar 21, 2026 at 02:55:33PM +0900, Michael Paquier wrote: > On Thu, Mar 19, 2026 at 12:25:41PM +0000, Bertrand Drouvot wrote: >> 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). > > I have checked after that, and did not spot an area (except your patch > of course). And applied this part. The main patch has some churn in proc.c and lock.c, moving some code blocks while the main focus of the patch is to add the two pgstat() calls to report some data, so I have moved this part into its own commit, and applied it. One thing to not in lock.c: we will calculate the time difference of the wait even if log_lock_waits is disabled, without the lock stats part. As this GUC is enabled by default, it does not matter much in practice, I guess, and it matters even less with the main patch merged. The implementation of the main patch is close enough to pgstat_io.c that your logic is a no-brainer (timestamp protected by the first LWLock, each field incremented depending on locktags, etc.). Instead of a boolean flag tracking if some stats have been set, we could also have used an approach like the checkpointer stats with is_all_zeros on the pending data, perhaps? At the end, with two incrementation routines, I've let the code as-is. Another thing I am not completely sure is if the sleep time of the isolation tests is long enough. I have tested things with CLOBBER_CACHE_ALWAYS to make the setup more sensitive to timings but could not get it to fail. We'll know soon enough if the buildfarm complains. After a few more tweaks here and there (code, comments, some beautification), done. -- 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