agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use single LWLock for lock statistics in pgstats
Date: Mon, 06 Apr 2026 05:03:25 +0000
Message-ID: <E1w9c7Q-003BZI-1q@gemulon.postgresql.org> (raw)

Use single LWLock for lock statistics in pgstats

Previously, one LWLock was used for each lock type, adding complexity
without an observable performance benefit as data is gathered only for
paths involving lock waits, at least currently.  This commit replaces
the per-type set of LWLocks with a single LWLock protecting the stats
data of all the lock types, like the stats kinds for SLRU or WAL.  A
good chunk of the callbacks get simpler thanks to this change.

The previous approach also had one bug in the flush callback when nowait
was called with "true": a backend iterating over all entries could
successfully flush some entries while skipping others due to contention,
then unconditionally reset the pending data.  This would cause some
stats data loss.

Oversight in 4019f725f5d4.

Reported-by: Tomas Vondra <tomas@vondra.me>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/1af63e6d-16d5-4d5b-9b03-11472ef1adf9@vondra.me

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/404a17c155ac6e80d990fb0625569a3854f7090d

Modified Files
--------------
src/backend/utils/activity/pgstat_lock.c | 86 +++++++++++---------------------
src/include/utils/pgstat_internal.h      |  7 +--
2 files changed, 31 insertions(+), 62 deletions(-)



Message-ID: <E1w9c7Q-003BZI-1q@gemulon.postgresql.org>
Permalink:  ../E1w9c7Q-003BZI-1q@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w9c7Q-003BZI-1q@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Use single LWLock for lock statistics in pgstats
  In-Reply-To: <E1w9c7Q-003BZI-1q@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox