From 4766e229c783c93caa7556bb11f5e80ac74b8b85 Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Thu, 24 Sep 2026 13:47:35 +0530 Subject: [PATCH v3] Don't log local statement and context with remote messages. Since 112faf1378ee, NOTICE, WARNING, and similar messages received over replication, postgres_fdw, and dblink connections are reported with ereport(LOG). LOG passes the default log_min_error_statement = error, so every such message was logged with a STATEMENT line carrying the full text of whatever local query was running, and, when received inside PL/pgSQL, with a CONTEXT line saying only where libpq happened to be reading input. Neither describes the remote message, and both are repeated for each one, so a query receiving many notices wrote several times the log volume of earlier releases and ran correspondingly slower. Suppress both with errhidestmt() and errhidecontext(), so each remote message is again a single log line. Reported-by: Merlin Moncure Author: Vignesh C Reviewed-by: Fujii Masao Tested-by: Merlin Moncure Discussion: https://postgr.es/m/CAHyXU0yDwOYkWpRi%3DgtpDwjBxVqeaezgkgZLRWm2p1_FgaiPFQ%40mail.gmail.com Backpatch-through: 19 --- src/include/libpq/libpq-be-fe-helpers.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/include/libpq/libpq-be-fe-helpers.h b/src/include/libpq/libpq-be-fe-helpers.h index cff68cd1c37..b0949280ce0 100644 --- a/src/include/libpq/libpq-be-fe-helpers.h +++ b/src/include/libpq/libpq-be-fe-helpers.h @@ -498,8 +498,15 @@ libpqsrv_notice_receiver(void *arg, const PGresult *res) if (len > 0 && message[len - 1] == '\n') len--; + /* + * Omit the local statement and context from each remote message. They can + * help identify the caller, but repeating them for every message could + * greatly increase log volume. + */ ereport(LOG, - errmsg_internal("%s: %.*s", prefix, len, message)); + errmsg_internal("%s: %.*s", prefix, len, message), + errhidestmt(true), + errhidecontext(true)); } #define PGresult libpqsrv_PGresult -- 2.55.0