Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVQuW-001xLn-2o for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 09:32:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVQuV-00BNn2-2R for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 09:32:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVQuV-00BNmu-0y for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 09:32:15 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wVQuT-00000001DNK-2KXB for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 09:32:14 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-36d5fd50d20so1046386a91.1 for ; Fri, 05 Jun 2026 02:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780651933; x=1781256733; darn=lists.postgresql.org; h=to:cc:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=LVbeXZcM9s8kqj1hvXEIjhg5ix4ay46bzpr+WUSCWUc=; b=YnKIUHWiOqNg6q8b75ZgCg05ElgmA5FGN73ssx+uGRi+m1hNPrGg79LGHhPBF2CT4J QswPSWFP03Vh5Lvj/jvd93xVyleeLjhUYOXjLB6pJXroDuo7TNhk2reFe22FBBFDsnBn rM2RWl1eGpbrYqy/Ow93GZ5oUvRhNh9+RPtRv/T7exMe2F2rLSvsEZVSfqNQJ+Fq10Xw rSNUxQwbsIbdSifVioE/c2J5TVWjo0Gp0l+0/IL0gcr0Isar0oBYoEyf2aO4zKqRVFsA bQW1XajJTZONc9VF66srDKye+XckI4Bdx6y93a8aIxTIa79eJEF8/1fOvjSvCDqIP3zY e+7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780651933; x=1781256733; h=to:cc:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LVbeXZcM9s8kqj1hvXEIjhg5ix4ay46bzpr+WUSCWUc=; b=Fb9rrx85hG2gAomFEo7RVDwQwHoFtR9TmoBEXtx/enXJVsBtD0DJEsJ3MBN8eW7D1w Iv66MSZf5Z4uWcmHTS8tfYuKJ2/YX+7i8rtLNFNDEIgoErEb3uQS9qN2bgCjb7LS+6Y+ WtpAuBVIf9CHYEluy9uMXRWMAJROeMbfz3HY1dBGvhr2uVVrEoiIhcDxrMJqN/y/2qOX a8Ckr13x/XCw3xTXxE/sY25Zp03lqyqWFFEeHMc0ET0L/W/+HZ5EmSeTdslYTR+Ga0kY 6UDIYbmlOPRRw7uFJoysb6GS9zaF5A0bWHBTrnQQXI6DUjYNWUfFJBftf0qdk9d8u3uB o4vQ== X-Gm-Message-State: AOJu0YyTBgHMIpCixb9UJEpVkJW0qdvoxgeKW/5pIZk0Pny0F0Gyt6ye JjymPDjIR6fHRIVEzH+DxR/TpxiIdd4KMCeynV29ielsLjyMzNgPwfnFELYyMIpW X-Gm-Gg: Acq92OH/Mv26U7rEzQyoEACiXWc43rwn9FnC8y9WUWslMI4YI5kMCDGvMEDvj3A9CX2 G57qknjKSmLMcS6s8Pe+/x7aT/bWRPnVZDQgbsAxHHlYODUVJfL4IJD41IU2BxDw/LrpVfRWw+Q mTm5i+a1/wYUQ6gYWn+dTY98j4tlYtYuK4cPJ+lr7DeTZhgA1+WZ/P6B4verQuSlX05AQf1biMy rcz7h1Z6cxUFM5CxJR+jKVIg4sd08nF2EEq/sWqOT50wilnm9i0t9Y4rdre3VDBBrpfVEEJVW7c duLhUnX8raOUKXs88mi4sFZfVHc6NOr7WqTk1wQAy7GyVeSrM0D7N/RyeUTiIzo/R/bG3smXPTx mS34AW0fkFwGjHbbtHXPuB5PU6+zmJ2qGo2xbixOzviXLxRI9a6IpD2qabjoPmECooOzEoRKuNH ovprNcYsjBT0HSIh93zIBT1s69Lte4Jn8ShAwXxBEK/Q== X-Received: by 2002:a05:6a21:a0b:b0:3b4:8fb2:a34b with SMTP id adf61e73a8af0-3b4ccdf040emr3439958637.11.1780651932412; Fri, 05 Jun 2026 02:32:12 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c85df0b2ddbsm7174546a12.24.2026.06.05.02.32.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2026 02:32:10 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_7BEA605F-B161-45DE-B191-52B0230EC6CC" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Prevent remote libpq notices from being sent to clients Message-Id: <396C3BEE-CD4D-450A-8D28-E708E9AA4075@gmail.com> Date: Fri, 5 Jun 2026 17:31:31 +0800 Cc: Fujii Masao , vignesh C To: Postgres hackers X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_7BEA605F-B161-45DE-B191-52B0230EC6CC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, This is another issue with =E2=80=9C[112faf137] Log remote NOTICE, = WARNING, and similar messages using ereport()=E2=80=9D. =46rom the = commit message, the intention of the feature is to log remote messages = with ereport() to get better formatting: ``` 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. ``` So remote messages should only be output to the server log, but = currently they can leak to the client if client_min_messages is set to = log. This is a simple repro: ``` evantest=3D# set client_min_messages=3Dlog; SET evantest=3D# select * from dblink('host=3Dlocalhost dbname=3Dpostgres=E2=80= =99, 'do $$ begin raise warning ''hello, client!!!''; end $$; select 1=E2=80=99= ) as t(x int); LOG: received message via remote connection: WARNING: hello, client!!! x --- 1 (1 row) ``` The one-line fix is straightforward, just change the ereport() level = from LOG to LOG_SERVER_ONLY. I also added a test in the patch. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_7BEA605F-B161-45DE-B191-52B0230EC6CC Content-Disposition: attachment; filename=v1-0001-Avoid-sending-remote-libpq-notices-back-to-client.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-Avoid-sending-remote-libpq-notices-back-to-client.patch" Content-Transfer-Encoding: quoted-printable =46rom=20be744e8ca867626f721ad146214cde9db395834e=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Fri,=205=20Jun=202026=2017:18:11=20+0800=0ASubject:=20[PATCH=20= v1]=20Avoid=20sending=20remote=20libpq=20notices=20back=20to=20clients=0A= =0ACommit=20112faf137=20added=20a=20custom=20libpq=20notice=20receiver=20= so=20that=20remote=0ANOTICE,=20WARNING,=20and=20similar=20messages=20= from=20dblink,=20postgres_fdw,=20and=0Areplication=20connections=20are=20= logged=20via=20ereport().=20The=20receiver=20used=20LOG,=0Awhich=20= preserves=20server=20logging,=20but=20LOG=20can=20also=20be=20sent=20to=20= the=20local=20SQL=0Aclient=20when=20client_min_messages=20is=20set=20to=20= log.=0A=0AThat=20exposes=20remote=20notices=20to=20the=20client=20as=20= local=20LOG=20messages,=20unlike=20the=0Aprevious=20libpq=20default=20= notice=20processor=20behavior,=20which=20printed=20them=20only=20to=0A= backend=20stderr.=0A=0AUse=20LOG_SERVER_ONLY=20instead.=20This=20keeps=20= the=20messages=20in=20the=20server=20log=20while=0Apreventing=20them=20= from=20being=20sent=20to=20the=20SQL=20client.=20Add=20a=20dblink=20= regression=0Atest=20for=20the=20client-visible=20case.=0A=0AAuthor:=20= Chao=20Li=20=0A---=0A=20= contrib/dblink/expected/dblink.out=20=20=20=20=20=20|=2012=20= ++++++++++++=0A=20contrib/dblink/sql/dblink.sql=20=20=20=20=20=20=20=20=20= =20=20|=20=208=20++++++++=0A=20src/include/libpq/libpq-be-fe-helpers.h=20= |=20=202=20+-=0A=203=20files=20changed,=2021=20insertions(+),=201=20= deletion(-)=0A=0Adiff=20--git=20a/contrib/dblink/expected/dblink.out=20= b/contrib/dblink/expected/dblink.out=0Aindex=201d2759def9e..835367b3668=20= 100644=0A---=20a/contrib/dblink/expected/dblink.out=0A+++=20= b/contrib/dblink/expected/dblink.out=0A@@=20-176,6=20+176,18=20@@=20= WHERE=20t.a=20>=207;=0A=20=209=20|=20j=20|=20{a9,b9,c9}=0A=20(2=20rows)=0A= =20=0A+--=20remote=20notices=20should=20be=20logged=20server-side=20only=0A= +SET=20client_min_messages=20=3D=20log;=0A+SELECT=20*=0A+FROM=20= dblink(connection_parameters(),=0A+=20=20=20=20=20=20=20=20=20=20=20=20= $$DO=20$do$=20BEGIN=20RAISE=20NOTICE=20'remote=20notice';=20END=20$do$;=20= SELECT=201$$)=0A+=20=20AS=20t(x=20int);=0A+=20x=20=0A+---=0A+=201=0A+(1=20= row)=0A+=0A+RESET=20client_min_messages;=0A=20--=20should=20generate=20= "connection=20not=20available"=20error=0A=20SELECT=20*=0A=20FROM=20= dblink('SELECT=20*=20FROM=20foo')=20AS=20t(a=20int,=20b=20text,=20c=20= text[])=0Adiff=20--git=20a/contrib/dblink/sql/dblink.sql=20= b/contrib/dblink/sql/dblink.sql=0Aindex=20d67a0a5992e..4c043a3ef87=20= 100644=0A---=20a/contrib/dblink/sql/dblink.sql=0A+++=20= b/contrib/dblink/sql/dblink.sql=0A@@=20-128,6=20+128,14=20@@=20SELECT=20= *=0A=20FROM=20dblink(connection_parameters(),'SELECT=20*=20FROM=20foo')=20= AS=20t(a=20int,=20b=20text,=20c=20text[])=0A=20WHERE=20t.a=20>=207;=0A=20= =0A+--=20remote=20notices=20should=20be=20logged=20server-side=20only=0A= +SET=20client_min_messages=20=3D=20log;=0A+SELECT=20*=0A+FROM=20= dblink(connection_parameters(),=0A+=20=20=20=20=20=20=20=20=20=20=20=20= $$DO=20$do$=20BEGIN=20RAISE=20NOTICE=20'remote=20notice';=20END=20$do$;=20= SELECT=201$$)=0A+=20=20AS=20t(x=20int);=0A+RESET=20client_min_messages;=0A= +=0A=20--=20should=20generate=20"connection=20not=20available"=20error=0A= =20SELECT=20*=0A=20FROM=20dblink('SELECT=20*=20FROM=20foo')=20AS=20t(a=20= int,=20b=20text,=20c=20text[])=0Adiff=20--git=20= a/src/include/libpq/libpq-be-fe-helpers.h=20= b/src/include/libpq/libpq-be-fe-helpers.h=0Aindex=20= cff68cd1c37..05b15118284=20100644=0A---=20= a/src/include/libpq/libpq-be-fe-helpers.h=0A+++=20= b/src/include/libpq/libpq-be-fe-helpers.h=0A@@=20-498,7=20+498,7=20@@=20= libpqsrv_notice_receiver(void=20*arg,=20const=20PGresult=20*res)=0A=20=09= if=20(len=20>=200=20&&=20message[len=20-=201]=20=3D=3D=20'\n')=0A=20=09=09= len--;=0A=20=0A-=09ereport(LOG,=0A+=09ereport(LOG_SERVER_ONLY,=0A=20=09=09= =09errmsg_internal("%s:=20%.*s",=20prefix,=20len,=20message));=0A=20}=0A=20= =0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_7BEA605F-B161-45DE-B191-52B0230EC6CC--