Re: Improve LWLock tranche name visibility across backends

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Improve LWLock tranche name visibility across backends
Date: 2025-07-10 08:52:08
Message-ID: aG9/OKQRgPUCxmsX@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2025-07-10 08:52:50 Re: A recent message added to pg_upgade
Previous Message Japin Li 2025-07-10 08:33:16 Re: [WIP]Vertical Clustered Index (columnar store extension) - take2