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 1wPd61-000uN9-2s for pgsql-hackers@arkaria.postgresql.org; Wed, 20 May 2026 09:20:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wPd5z-006s49-2P for pgsql-hackers@arkaria.postgresql.org; Wed, 20 May 2026 09:20:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wPd5z-006s41-1V for pgsql-hackers@lists.postgresql.org; Wed, 20 May 2026 09:20:08 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wPd5y-00000000Wbz-0akM for pgsql-hackers@postgresql.org; Wed, 20 May 2026 09:20:07 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7dcdd23fcdfso2346619a34.3 for ; Wed, 20 May 2026 02:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779268804; cv=none; d=google.com; s=arc-20240605; b=kaSJ1S+A/OP7VHB23Pv+k+Njmle6snSc/kzNFbpCzjqd9LwFcNszne0OLzKbzC9JD2 riz7Hx1tckrCTEHeRlr/FTx1LU6HxnVCswSkBee4pefVBnmU2tve1ajxFx7sPy9hnoJO Jh/KFV8AabebAe3E6InlPVfz/BV+S+9CEA/OykH066cFd7CRVI2bLPCFPCi0QUIjdDS0 GzmOBMoflhS4SLGacjkCFcrqAHtDeusDWf/B+J/PIDzYG5CO0l47Ae6dgueRmaxuzGAr 4+t8LPrLCKSdFGtLbiViWKPSmzeSLvzNr7cZS80zrNsRxM+VY0cmGMQzcb6z79NaQU5G 9tnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MYc5xfjawPc7rHJlsRXk5lIjmf7ND65tuB4tfadDmMo=; fh=z/PosFAi6xtW4tAEaCsyhSDBqgWok/iTXZWzUFGuKlM=; b=T+2G/WZ0ImfJb3pY/tO/ppNHbzvqDYMClmyIO7ImFK/HLCP1hvzDp6R2iqQzBsOdW1 pdQythmypst1gBGpEokaauEzw5iJ8sk0/xyIfO5Sd4uOJnZV3ibI9QaCWym2woqJwiog 34uiKm3e+e6plrRcRbn/yDphVKNQNkq+vSOj+tDxcbWK92vVYIPVaLoPBi5YbUlckIXI MF0C/ipMLHKKfEQQ7oj4bUnOywTM6a7Ep652avMFF062spUdljGnW+8a3E847bY0Kb00 oCU97zOapsj7Q44EDBjFAcRWTYKPgt3W3sCvHjmqGnozFxmTKZviKgUDf+MT244lVRNE i4Pw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779268804; x=1779873604; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MYc5xfjawPc7rHJlsRXk5lIjmf7ND65tuB4tfadDmMo=; b=Qzd/qN30pqz+Gykor1ILkKLeW8rN4JqiPWH4/rNT6gmkjFK/IwUKb5GSOp/4WzfPjU Em+N0PBcO6pkAx8g6PhmVEY/GVeq3USUDJKfAp8RTh8QLYxIBOYUB9AW5JaZ+yfZh6cB V3wKiEL2JQRn4i+kPWKES62LvJb/AC4BMpU3YexN1XqBNDUDExJwcJe1VFVOtkVewKT9 GGanaDW1nPvxTKeOFqLa4FTdFEUZ6zgKq8H1zrNQBk5D2NOEggUlzCKHmZFrk7zy1t93 nPtjF5ifeLR/7P5gLB/x1yXipTkYxY3wnuLLcTsw4T3sSFOZnLrsujaOUA6PQ6JAu2jY MUsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779268804; x=1779873604; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MYc5xfjawPc7rHJlsRXk5lIjmf7ND65tuB4tfadDmMo=; b=JbfwIulOyFMlgDzQkud3C1OASI3G+4GF6imp/T26bgZ7pOdHWUxnoYuo7af1x9BBVB FpTDVMCoiySH/RRPCU9wmPB1FgIPhVI5JwBjDqGwI4TlABj4A/uw4zS6IXbZE+PlHXCw iPCchslBuTSBt+HeubvfWe7OBvaF/zxk3sZRfg85/giBqvic8noCbxqv1yWSH9Ey8PLf nI390t5WytIfEqCW3hGcZstu4uIzO0AYfW5oMb+k+Vd0qBxVs7ofKscceF5O2znKUsmq 6dTvMrKHtoj4oKenQNbCkG9ZW9noI4bZmHVzjoolIKcXN6ee1g7PMrP9SRRx84qWIghE x9tg== X-Gm-Message-State: AOJu0YwwpVgP44hAUwGveMSOZR39ND4r2fY6aDBSpLrwwaM5etvKKykd 8rfK1kDTlKptECwSHFzEVi6ss2aPElxSg1njg5yDDoORVfPRFEpvJA7mESZR1wsJiW+XmXsbYUz XQrrQg8aetq6DLvjX2PnWcAy2LZpMoQI= X-Gm-Gg: Acq92OHobgf/7zYdBMJSDHLPmtUQBMJ3VD1FEk4qzQS17bvQRQ4V09vVZkWwL7ktAeW AmgxNZl8yIpYfSXrHO1AAjQStn/weCzbSJuWAK1i2VCMlQ3CDZAvnqApF9JoLlExz5bvYC7AI7g W+E3uSIyHczlvmNenfGw+pkjRgukf/hCP7jDCm02pxiB196XcfXVJ6X5UccMbMrD42cONBShmFF LGCbhbdhB76okI1YXMrHZuNNM2kB+3N/oBB3iSass76V4SgXqAjb8p0+VIfqlUixm8WUR8QYuK4 wOQwIMG7pvsBv+C8z9+/AHfG9H5eVaK2ojLDTVU7U1BubG0+hc4J X-Received: by 2002:a05:6820:220e:b0:689:dfc8:5e3c with SMTP id 006d021491bc7-69c942aede9mr14340925eaf.3.1779268803872; Wed, 20 May 2026 02:20:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fujii Masao Date: Wed, 20 May 2026 18:19:51 +0900 X-Gm-Features: AVHnY4LqFJVuySyyCfEZzeG8Uf8x7IZH8_2ILeg2GQnqwNuEDsMdQmf1QnMGbYg Message-ID: Subject: Re: Set notice receiver before libpq connection startup To: Chao Li Cc: PostgreSQL-development , vignesh C Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, May 20, 2026 at 4:21=E2=80=AFPM Chao Li wr= ote: > > Hi, > > While testing =E2=80=9CLog remote NOTICE, WARNING, and similar messages u= sing ereport()=E2=80=9D, I noticed that libpqsrv_notice_receiver is only in= stalled after libpqsrv_connect() finishes. As a result, NOTICE messages gen= erated during connection establishment are missed by ereport() and are stil= l printed to stderr. > > To reproduce the issue, I created a separate database called remotedb and= defined a login trigger that emits a NOTICE message: > ``` > CREATE DATABASE remotedb; > > \c remotedb > > CREATE OR REPLACE FUNCTION repro_login_notice() > RETURNS event_trigger > LANGUAGE plpgsql AS $$ > BEGIN > RAISE NOTICE 'startup notice from remotedb login trigger'; > END; > $$; > > CREATE EVENT TRIGGER repro_login_notice_trg > ON login > EXECUTE FUNCTION repro_login_notice(); > > ALTER EVENT TRIGGER repro_login_notice_trg ENABLE ALWAYS; > ``` > > Then, from another database: > ``` > evantest=3D# create extension dblink; > CREATE EXTENSION > evantest=3D# SELECT dblink_connect('host=3D127.0.0.1 port=3D5432 dbname= =3Dremotedb user=3Dchaol sslmode=3Ddisable gssencmode=3Ddisable'); > dblink_connect > ---------------- > OK > (1 row) > ``` > > In the system log, the NOTICE message is printed directly: > ``` > 2026-05-20 13:02:19.350 CST [24909] STATEMENT: SELECT dblink_connect('ho= st=3D127.0.0.1 port=3D5432 dbname=3Dremotedb user=3Dchaol sslmode=3Ddisable= gssencmode=3Ddisable'); > NOTICE: startup notice from remotedb login trigger > ``` > > To fix that, I think we should install libpqsrv_notice_receiver before li= bpqsrv_connect_internal(). In the attached patch, I added two helpers: libp= qsrv_connect_with_notice_receiver() and libpqsrv_connect_params_with_notice= _receiver(). > > With the fix, the NOTICE message now looks like this: > ``` > 2026-05-20 14:44:49.296 CST [45567] LOG: received message via remote con= nection: NOTICE: startup notice from remotedb login trigger > 2026-05-20 14:44:49.296 CST [45567] STATEMENT: SELECT dblink_connect('ho= st=3D127.0.0.1 port=3D5432 dbname=3Dremotedb user=3Dchaol sslmode=3Ddisable= gssencmode=3Ddisable'); > ``` > > Please see the attached patch for details. Thanks for the report and patch! I'd prefer to avoid adding notice-receiver-specific wrappers such as libpqsrv_connect_with_notice_receiver(). Instead, how about splitting libpqsrv_connect() into two steps: libpqsrv_connect_start(), which performs libpqsrv_connect_prepare() and PQconnectStart(), and libpqsrv_connect_complete(), which runs libpqsrv_connect_internal()? With this approach, callers could invoke PQsetNoticeReceiver() after libpqsrv_connect_start() returns but before libpqsrv_connect_complete() is called. This would allow startup-time notices to be handled correctly witho= ut introducing a dedicated wrapper function. Compared to the *_with_notice_receiver() approach, this design is more general because it exposes the phase between PQconnectStart() and connectio= n completion. It could also support other kinds of per-connection setup in th= e future, not just notice receiver installation. Thought? Regards, --=20 Fujii Masao