public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: [email protected]
Subject: pgsql: Set notice receiver before libpq connection startup completes
Date: Fri, 22 May 2026 15:27:43 +0000
Message-ID: <[email protected]> (raw)

Set notice receiver before libpq connection startup completes

Commit 112faf1378e added custom notice receivers for replication,
postgres_fdw, and dblink so that remote NOTICE, WARNING, and similar
messages are reported via ereport(). However, those notice receivers were
installed only after libpqsrv_connect() and libpqsrv_connect_params()
returned, by which point libpq connection startup had already completed.
As a result, messages emitted during connection establishment could be
missed.

This commit fixes the issue by splitting libpqsrv_connect() and
libpqsrv_connect_params() into separate start and complete phases:
libpqsrv_connect_start(), libpqsrv_connect_params_start(), and
libpqsrv_connect_complete(). This allows callers to perform
per-connection setup, such as installing a notice receiver, after the
connection has been started but before startup completes.

Note that callers of libpqsrv_connect_start() and
libpqsrv_connect_params_start() must still call
libpqsrv_connect_complete(), even if the start function returns NULL, so
that any external FDs reserved during startup are released properly.

Author: Chao Li <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Vignesh C <[email protected]>
Reviewed-by: Rafia Sabih <[email protected]>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/06a5c3cdef024630aef0992bb7b471459aa2b70f

Modified Files
--------------
contrib/dblink/dblink.c                            | 17 +++---
contrib/postgres_fdw/connection.c                  | 13 +++--
.../libpqwalreceiver/libpqwalreceiver.c            | 12 ++--
src/include/libpq/libpq-be-fe-helpers.h            | 65 ++++++++++++++++------
4 files changed, 70 insertions(+), 37 deletions(-)



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: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: Set notice receiver before libpq connection startup completes
  In-Reply-To: <[email protected]>

* 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