]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Set notice receiver before libpq connection startup completes
authorFujii Masao <fujii@postgresql.org>
Fri, 22 May 2026 15:25:48 +0000 (00:25 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 22 May 2026 15:25:48 +0000 (00:25 +0900)
commit06a5c3cdef024630aef0992bb7b471459aa2b70f
tree568aba34f4c597170bc960a5b342e659d9bf04d8
parentd8b5d87e545c340b129150d7214bff15275e2634
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 <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Rafia Sabih <rafia.pghackers@gmail.com>
Discussion: https://postgr.es/m/A2B8B7DE-C119-492F-A9FA-14CF86849777@gmail.com
contrib/dblink/dblink.c
contrib/postgres_fdw/connection.c
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
src/include/libpq/libpq-be-fe-helpers.h