From be744e8ca867626f721ad146214cde9db395834e Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Fri, 5 Jun 2026 17:18:11 +0800 Subject: [PATCH v1] Avoid sending remote libpq notices back to clients Commit 112faf137 added a custom libpq notice receiver so that remote NOTICE, WARNING, and similar messages from dblink, postgres_fdw, and replication connections are logged via ereport(). The receiver used LOG, which preserves server logging, but LOG can also be sent to the local SQL client when client_min_messages is set to log. That exposes remote notices to the client as local LOG messages, unlike the previous libpq default notice processor behavior, which printed them only to backend stderr. Use LOG_SERVER_ONLY instead. This keeps the messages in the server log while preventing them from being sent to the SQL client. Add a dblink regression test for the client-visible case. Author: Chao Li --- contrib/dblink/expected/dblink.out | 12 ++++++++++++ contrib/dblink/sql/dblink.sql | 8 ++++++++ src/include/libpq/libpq-be-fe-helpers.h | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out index 1d2759def9e..835367b3668 100644 --- a/contrib/dblink/expected/dblink.out +++ b/contrib/dblink/expected/dblink.out @@ -176,6 +176,18 @@ WHERE t.a > 7; 9 | j | {a9,b9,c9} (2 rows) +-- remote notices should be logged server-side only +SET client_min_messages = log; +SELECT * +FROM dblink(connection_parameters(), + $$DO $do$ BEGIN RAISE NOTICE 'remote notice'; END $do$; SELECT 1$$) + AS t(x int); + x +--- + 1 +(1 row) + +RESET client_min_messages; -- should generate "connection not available" error SELECT * FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[]) diff --git a/contrib/dblink/sql/dblink.sql b/contrib/dblink/sql/dblink.sql index d67a0a5992e..4c043a3ef87 100644 --- a/contrib/dblink/sql/dblink.sql +++ b/contrib/dblink/sql/dblink.sql @@ -128,6 +128,14 @@ SELECT * FROM dblink(connection_parameters(),'SELECT * FROM foo') AS t(a int, b text, c text[]) WHERE t.a > 7; +-- remote notices should be logged server-side only +SET client_min_messages = log; +SELECT * +FROM dblink(connection_parameters(), + $$DO $do$ BEGIN RAISE NOTICE 'remote notice'; END $do$; SELECT 1$$) + AS t(x int); +RESET client_min_messages; + -- should generate "connection not available" error SELECT * FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[]) diff --git a/src/include/libpq/libpq-be-fe-helpers.h b/src/include/libpq/libpq-be-fe-helpers.h index cff68cd1c37..05b15118284 100644 --- a/src/include/libpq/libpq-be-fe-helpers.h +++ b/src/include/libpq/libpq-be-fe-helpers.h @@ -498,7 +498,7 @@ libpqsrv_notice_receiver(void *arg, const PGresult *res) if (len > 0 && message[len - 1] == '\n') len--; - ereport(LOG, + ereport(LOG_SERVER_ONLY, errmsg_internal("%s: %.*s", prefix, len, message)); } -- 2.50.1 (Apple Git-155)