Re: Improve LWLock tranche name visibility across backends
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-07-10T08:52:08Z
Lists: pgsql-hackers
Hi, On Wed, Jul 09, 2025 at 04:39:48PM -0500, Sami Imseih wrote: > Hi, > > When querying pg_stat_activity, the function pgstat_get_wait_event is > called, which internally uses GetLWLockIdentifier and GetLWTrancheName > to map the LWLock to its tranche name. If the backend does not recognize > the tranche ID, a fallback name "extension" is used. Therefore, backends > that have registered the tranche will report the correct extension-defined > tranche name, while others will report the generic fallback of "extension". > > i.e. > ```` > postgres=# select wait_event, wait_event_type from pg_stat_activity; > -[ RECORD 1 ]---+-------------------- > wait_event | extension > wait_event_type | LWLock > ``` > instead of > ``` > postgres=# select wait_event, wait_event_type from pg_stat_activity; > -[ RECORD 1 ]---+-------------------- > wait_event | MyUsefulExtension > wait_event_type | LWLock > ``` > > This is the current design, but I think we can do better to avoid inconsitencies > this my lead for monitoring tools and diagnostics. +1 on finding a way to improve this, thanks for looking at it. > Attached is a proof of concept that does not alter the > LWLockRegisterTranche API. Instead, it detects when a registration is > performed by a normal backend and stores the tranche name in shared memory, > using a dshash keyed by tranche ID. Tranche name lookup now proceeds in > the order of built-in names, the local list, and finally the shared memory. > The fallback name "extension" can still be returned if an extension does > not register a tranche. I did not look in details, but do you think we could make use of WaitEventCustomNew()? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Commits
-
test_dsa: Avoid leaking LWLock tranches.
- c5c74282f2ea 19 (unreleased) landed
-
Teach DSM registry to ERROR if attaching to an uninitialized entry.
- b26d76f64327 18.2 landed
- ac2800ddc185 17.8 landed
- 1165a933aab1 19 (unreleased) landed
-
Add a test harness for the LWLock tranche code.
- 16607718c010 19 (unreleased) landed
-
Revert recent change to RequestNamedLWLockTranche().
- d814d7fc3d52 19 (unreleased) landed
-
Move dynamically-allocated LWLock tranche names to shared memory.
- 38b602b0289f 19 (unreleased) landed
-
Prepare DSM registry for upcoming changes to LWLock tranche names.
- 5487058b56e0 19 (unreleased) landed
-
Add GetNamedDSA() and GetNamedDSHash().
- fe07100e82b0 19 (unreleased) cited