Re: alert clients when prepared statements are deallocated

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: alert clients when prepared statements are deallocated
Date: 2026-06-02 22:11:52
Message-ID: ah9VKGwwlgqF-hi7@nathan
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I've spent quite a bit of time on this one. Attached is a new version of
the patch. A few notes:

* This version uses a protocol extension instead of bumping the protocol
version. It looks like this is the first such extension, so it's entirely
possible I'm missing something. Note that this should work for any version
of PostgreSQL released since 2018 (see commit ae65f6066d), but IIUC older
versions will error on the protocol extension. I'm a little concerned that
this could break pg_upgrade from early versions of v10 (which will be the
minimum supported source version in v20), so we might need to provide a way
to disable it in libpq.

* I sketched out an alternative design that would allow client applications
to retrieve the notifications at their leisure, but I stopped when I
realized this would actually add quite a bit of complexity. We have to
think about duplicate reports, specifying which statements to collect,
clearing reports, and other subtle behavior. I'm hopeful that the callback
mechanism is good enough for now. If feedback indicates it is not, we can
certainly re-evaluate as a follow-up effort.

* I didn't add notifications for unnamed prepared statements. I'm not
seeing a real use-case for that, but I admittedly haven't thought about it
too hard.

* I haven't added any tests in this patch. My thinking is that it will get
tested as part of the libpq-LO-interface revamp in the other thread.

* I'm a little worried about race conditions involving a client trying to
use a statement while a deallocation message is in flight, but I haven't
identified anything concrete so far. This is something I'd like to
investigate some more, though.

--
nathan

Attachment Content-Type Size
v3-0001-tell-client-when-prepared-statements-are-dealloca.patch text/plain 21.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2026-06-02 22:13:03 Re: Wrong unsafe-flag test in check_output_expressions()
Previous Message Michael Paquier 2026-06-02 22:10:23 Re: [PATCH] Fix libxml leaks in contrib/xml2 XPath functions