pgsql: Log remote NOTICE, WARNING, and similar messages using ereport()
Log remote NOTICE, WARNING, and similar messages using ereport().
Previously, NOTICE, WARNING, and similar messages received from remote
servers over replication, postgres_fdw, or dblink connections were printed
directly to stderr on the local server (e.g., the subscriber). As a result,
these messages lacked log prefixes (e.g., timestamp), making them harder
to trace and correlate with other log entries.
This commit addresses the issue by introducing a custom notice receiver
for replication, postgres_fdw, and dblink connections. These messages
are now logged via ereport(), ensuring they appear in the logs with proper
formatting and context, which improves clarity and aids in debugging.
Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: /messages/by-id/CALDaNm2xsHpWRtLm-VL_HJCsaE3+1Y_n-jDEAr3-suxVqc3xoQ@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/112faf1378ee62db75cd9e3223c86bf53b8c2736
Modified Files
--------------
contrib/dblink/dblink.c | 7 +++++
contrib/postgres_fdw/connection.c | 3 +++
.../libpqwalreceiver/libpqwalreceiver.c | 3 +++
src/include/libpq/libpq-be-fe-helpers.h | 30 ++++++++++++++++++++++
4 files changed, 43 insertions(+)
On 22/7/2025 07:22, Fujii Masao wrote:
Log remote NOTICE, WARNING, and similar messages using ereport().
Previously, NOTICE, WARNING, and similar messages received from remote
servers over replication, postgres_fdw, or dblink connections were printed
directly to stderr on the local server (e.g., the subscriber). As a result,
these messages lacked log prefixes (e.g., timestamp), making them harder
to trace and correlate with other log entries.This commit addresses the issue by introducing a custom notice receiver
for replication, postgres_fdw, and dblink connections. These messages
are now logged via ereport(), ensuring they appear in the logs with proper
formatting and context, which improves clarity and aids in debugging.
Perhaps I'm wrong, but it seems to me that you also need to add the
libintl link to the Makefile of each module that uses the
libpqsrv_notice_receiver routine.
At least, without this patch, I can't build master under MacOS:
Undefined symbols for architecture x86_64:
"_libintl_gettext", referenced from:
_libpqsrv_notice_receiver in dblink.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
--
regards, Andrei Lepikhov
Attachments:
v0-0001-Fix-Makefile-in-modules-employing-the-libpqsrv_no.patchtext/plain; charset=UTF-8; name=v0-0001-Fix-Makefile-in-modules-employing-the-libpqsrv_no.patchDownload
From 6a577860c0a7eaadd43d931f737ff5f2a954b597 Mon Sep 17 00:00:00 2001
From: "Andrei V. Lepikhov" <lepihov@gmail.com>
Date: Tue, 22 Jul 2025 14:25:48 +0200
Subject: [PATCH v0] Fix Makefile in modules employing the
libpqsrv_notice_receiver function
---
contrib/dblink/Makefile | 1 +
contrib/postgres_fdw/Makefile | 1 +
2 files changed, 2 insertions(+)
diff --git a/contrib/dblink/Makefile b/contrib/dblink/Makefile
index fde0b49ddbb..ea6396bc70c 100644
--- a/contrib/dblink/Makefile
+++ b/contrib/dblink/Makefile
@@ -6,6 +6,7 @@ OBJS = \
dblink.o
PG_CPPFLAGS = -I$(libpq_srcdir)
SHLIB_LINK_INTERNAL = $(libpq)
+SHLIB_LINK = $(filter -lintl, $(LIBS))
EXTENSION = dblink
DATA = dblink--1.2.sql dblink--1.1--1.2.sql dblink--1.0--1.1.sql
diff --git a/contrib/postgres_fdw/Makefile b/contrib/postgres_fdw/Makefile
index adfbd2ef758..bba2551df51 100644
--- a/contrib/postgres_fdw/Makefile
+++ b/contrib/postgres_fdw/Makefile
@@ -12,6 +12,7 @@ PGFILEDESC = "postgres_fdw - foreign data wrapper for PostgreSQL"
PG_CPPFLAGS = -I$(libpq_srcdir)
SHLIB_LINK_INTERNAL = $(libpq)
+SHLIB_LINK = $(filter -lintl, $(LIBS))
EXTENSION = postgres_fdw
DATA = postgres_fdw--1.0.sql postgres_fdw--1.0--1.1.sql postgres_fdw--1.1--1.2.sql
--
2.50.1
On 2025-Jul-22, Andrei Lepikhov wrote:
Perhaps I'm wrong, but it seems to me that you also need to add the libintl
link to the Makefile of each module that uses the libpqsrv_notice_receiver
routine.
That would amount to supporting translations of contrib modules, but
there's actually a bunch of additional work to do if we want to do that.
IMO the proper fix for this, at least for now, is to remove it:
/messages/by-id/202507221147.sdg2rmhbqb5z@alvherre.pgsql
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
On Tue, Jul 22, 2025 at 9:30 PM Andrei Lepikhov <lepihov@gmail.com> wrote:
On 22/7/2025 07:22, Fujii Masao wrote:
Log remote NOTICE, WARNING, and similar messages using ereport().
Previously, NOTICE, WARNING, and similar messages received from remote
servers over replication, postgres_fdw, or dblink connections were printed
directly to stderr on the local server (e.g., the subscriber). As a result,
these messages lacked log prefixes (e.g., timestamp), making them harder
to trace and correlate with other log entries.This commit addresses the issue by introducing a custom notice receiver
for replication, postgres_fdw, and dblink connections. These messages
are now logged via ereport(), ensuring they appear in the logs with proper
formatting and context, which improves clarity and aids in debugging.Perhaps I'm wrong, but it seems to me that you also need to add the
libintl link to the Makefile of each module that uses the
libpqsrv_notice_receiver routine.
At least, without this patch, I can't build master under MacOS:Undefined symbols for architecture x86_64:
"_libintl_gettext", referenced from:
_libpqsrv_notice_receiver in dblink.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
This issue is currently being discussed in thread [1]/messages/by-id/0e6299d9-608a-4ffa-aeb1-40cb8a99000b@oss.nttdata.com. The consensus there is
to remove the translation-related changes (like the translation marker)
introduced by the original commit to resolve the problem.
Regards,
[1]: /messages/by-id/0e6299d9-608a-4ffa-aeb1-40cb8a99000b@oss.nttdata.com
--
Fujii Masao