agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Masahiko Sawada <msawada@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix memory leak in pgoutput with streamed prepared transactions.
Date: Fri, 18 Sep 2026 17:19:56 +0000
Message-ID: <E1x7cFg-00000000Hxp-3NN3@gemulon.postgresql.org> (raw)

Fix memory leak in pgoutput with streamed prepared transactions.

pgoutput records the toplevel XID in the relation's streamed_txns
list, allocated in CacheMemoryContext, when it sends a relation's
schema during a streamed transaction. We clean up that list at stream
commit and stream abort, but missed stream prepare, so the XIDs stay
around until a relcache invalidation for the relation or until the
walsender exits.

Fix by cleaning up the cache after writing the stream prepare message,
marking the schema as sent as we do at stream commit. The subscriber
applies the spooled relation messages at PREPARE time and its relation
map isn't rolled back by ROLLBACK PREPARED, so we don't need to send
the schema again even if the prepared transaction eventually aborts.

Oversight in commit 63cf61cdeb7b.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWWt5aaKHCnV=jNOwABzspd-WbnhWLndDqtESDQRQ-BkKQ@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/274da088e021a92e2ffd2b8938a7b978b2cf11b3

Modified Files
--------------
src/backend/replication/pgoutput/pgoutput.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)



view thread (6+ messages)

Message-ID: <E1x7cFg-00000000Hxp-3NN3@gemulon.postgresql.org>
Permalink:  ../E1x7cFg-00000000Hxp-3NN3@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x7cFg-00000000Hxp-3NN3@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: msawada@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix memory leak in pgoutput with streamed prepared transactions.
  In-Reply-To: <E1x7cFg-00000000Hxp-3NN3@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