pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Floris Van Nee <florisvannee@optiver.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: exclusion@gmail.com <exclusion@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #17947: Combination of replslots pgstat issues causes error/assertion failure
Date: Wed, 5 Jun 2024 15:23:21 +0900
Message-ID: <ZmAEWcFYIhnHMs7C@paquier.xyz> (raw)
In-Reply-To: <Zl6lQ_K0-QOfqUS4@paquier.xyz>
References: <17947-b9554521ad963c9c@postgresql.org>
	<20230601.084245.1524588196504400333.horikyota.ntt@gmail.com>
	<20240505183741.5tefii3razzefvtc@awork3.anarazel.de>
	<dd4c68beba5c40c5a7946569d450ec59@Optiver.com>
	<Zl6lQ_K0-QOfqUS4@paquier.xyz>

On Tue, Jun 04, 2024 at 02:25:23PM +0900, Michael Paquier wrote:
>> This does mean it's unfortunately unrelated to the issue I reported
>> here
>> https://www.postgresql.org/message-id/flat/20240505223546.6yvjzgqifuoiii3e%40awork3.anarazel.de#1dfe...
>> , because the issue in the current thread is fixed by changing a
>> replication-slot call (which is not used in the database for which I
>> reported it).
> 
> Yeah, It's clear that we don't have enough information to proceed
> here.  It seems to me that there is a good argument for addressing
> this one first, separately of the other one.

I have been playing with this patch and scenarios of replslot
create/drop similar to what's been sent at the top of this thread, and
the solution proposed is proving to be stable enough to not see a
problem in the pgstats machinery after letting the test run 30 minutes
or so (switched sleep intervals for one).

Attached is an updated patch with refined comments at the top of
pgstat_drop_entry(), to be applied to 15~.

I'm kind of feeling that this is not the end of it, even if the use of
the drop routine is inconsistent in this code path.  Perhaps that's
just my spidey sense being incorrect here..
--
Michael

Attachments:

v2-0001-Notify-stats-gc-when-dropping-logical-replication.patch (text/x-diff, 2.1K) download From 290cc849f222680bf5f69303ed368ada6bb3eed4 Mon Sep 17 00:00:00 2001 From: Floris van Nee <florisvannee@optiver.com> Date: Sun, 2 Jun 2024 22:35:44 +0200 Subject: [PATCH v2] Notify stats gc when dropping logical replication slot pgstat_drop_replslot calls pgstat_drop_entry without checking the result. If pgstat_drop_entry cannot free the entry from shared memory completely, the gc function must be called to flag it for other backends. This is similar to what AtEOXact_PgStat_DroppedStats and similar functions do. --- src/backend/utils/activity/pgstat_replslot.c | 5 +++-- src/backend/utils/activity/pgstat_shmem.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index 889e86ac5a..da11b86744 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -157,8 +157,9 @@ pgstat_drop_replslot(ReplicationSlot *slot) { Assert(LWLockHeldByMeInMode(ReplicationSlotAllocationLock, LW_EXCLUSIVE)); - pgstat_drop_entry(PGSTAT_KIND_REPLSLOT, InvalidOid, - ReplicationSlotIndex(slot)); + if (!pgstat_drop_entry(PGSTAT_KIND_REPLSLOT, InvalidOid, + ReplicationSlotIndex(slot))) + pgstat_request_entry_refs_gc(); } /* diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 91591da395..4a4b69891d 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -855,6 +855,17 @@ pgstat_drop_database_and_contents(Oid dboid) pgstat_request_entry_refs_gc(); } +/* + * Drop a single stats entry. + * + * This routine returns false if the stats entry of the dropped object could + * not be freed, true otherwise. + * + * The callers of this function should call pgstat_request_entry_refs_gc() + * if the stats entry could not be freed, to ensure that this entry's memory + * can be reclaimed later by a different backend calling + * pgstat_gc_entry_refs(). + */ bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid) { -- 2.43.0
signature.asc (application/pgp-signature, 832B) download

view thread (9+ messages)  latest in thread

Message-ID: <ZmAEWcFYIhnHMs7C@paquier.xyz>
Permalink:  ../ZmAEWcFYIhnHMs7C@paquier.xyz/
Also on:    postgresql.org/message-id/ZmAEWcFYIhnHMs7C@paquier.xyz

 ·  · 

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-bugs@postgresql.org
  Cc: michael@paquier.xyz, florisvannee@optiver.com, andres@anarazel.de, horikyota.ntt@gmail.com, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17947: Combination of replslots pgstat issues causes error/assertion failure
  In-Reply-To: <ZmAEWcFYIhnHMs7C@paquier.xyz>

* 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