pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve consistency of replication slot statistics
Date: Mon, 11 Mar 2024 01:26:50 +0000
Message-ID: <E1rjURG-0039Iq-6c@gemulon.postgresql.org> (raw)

Improve consistency of replication slot statistics

The replication slot stats stored in shared memory rely on an internal
index number.  Both pgstat_reset_replslot() and pgstat_fetch_replslot()
lacked some LWLock protections with ReplicationSlotControlLock while
operating on these index numbers.  This issue could cause these two
functions to potentially operate on incorrect slots when taken in
isolation in the event of slots dropped and/or re-created concurrently.

Note that pg_stat_get_replication_slot() is called once per slot when
querying pg_stat_replication_slots, meaning that the stats are retrieved
across multiple ReplicationSlotControlLock acquisitions.  So, while this
commit improves more consistency, it may still be possible that
statistics are not completely consistent for a single scan of
pg_stat_replication_slots under concurrent replication slot drop or
creation activity.

The issue should unlikely be a problem in practice, causing the report
of inconsistent stats or or the stats reset of an incorrect slot, so no
backpatch is done.

Author: Bertrand Drouvot
Reviewed-by: Heikki Linnakangas, Shveta Malik, Michael Paquier
Discussion: https://postgr.es/m/ZeGq1HDWFfLkjh4o@ip-10-97-1-34.eu-west-3.compute.internal

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b36fbd9f8da140f5b0ef9f7daa6b3cb4cae8a69b

Modified Files
--------------
src/backend/utils/activity/pgstat_replslot.c | 42 +++++++++++++++++-----------
1 file changed, 25 insertions(+), 17 deletions(-)



view thread (3+ messages)

Message-ID: <E1rjURG-0039Iq-6c@gemulon.postgresql.org>
Permalink:  ../E1rjURG-0039Iq-6c@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rjURG-0039Iq-6c@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: Improve consistency of replication slot statistics
  In-Reply-To: <E1rjURG-0039Iq-6c@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox