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 1wPxiI-001B7G-16 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2026 07:21:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wPxiE-009YZg-2w for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2026 07:20:59 +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 1wPxiE-009YZU-1c for pgsql-hackers@lists.postgresql.org; Thu, 21 May 2026 07:20:59 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wPxiB-0000000043u-3dTG for pgsql-hackers@postgresql.org; Thu, 21 May 2026 07:20:58 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-82f8b60e54dso4856005b3a.2 for ; Thu, 21 May 2026 00:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779348054; x=1779952854; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2GEUVeek1KzPPT6YMF1XdkscpkeFpJ+DU40ycY0S/w8=; b=LmvB2lz532X1G5f2rO6X65s7kfFSJIw6R/Fn/9+S/zvDGMX/A9k3MPwjLSrQvEHqGo 94J9k4OHLJNFZFBFXiwgQE6bxgGXbsj2G/4r/016wgfm/U6D+0bO0MxkLv75wA2uc3sD OcsWMd4FCXlvJkIAQj4BuiHu6OPnJeObCAhWrQAo8pcpOY31oDPOGjF42E+KEUTZfW7W GQeOQxe8ZY76Wylx6hMJKpM7+t4Dx3Tq5yu8N1rvuO8Zqr4Wv07fbBDBMH1ZtQnsjPSX C2TfaniW5Ys+yeVzGNa3rO870HTU1dvCzIsJhhy2ICr3mGhIaEtmzNm2Oua/n5Kfdb72 Wdsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779348054; x=1779952854; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2GEUVeek1KzPPT6YMF1XdkscpkeFpJ+DU40ycY0S/w8=; b=FlBIVgCMEHN3m67YYJQlkls+4oKLCi7QKIRZBi4i7fo8JUosuyZ0jBy2IQvRGwANzk 2wk89hAMnK23NlAy94wamk37c0JHXRm3ue5F0ql/vnmP+JEdcCb2N4yTXh71GBz5iJmv 9elkHyS96nvjTvHGe1msSUYCB46gepLsAMZyUL8AHRg1BEGnkxiPrxU0roUF8YxHSrR3 v4XWGJPtLc41U1AWEZaOaF0bJdeRXGGQzxQD+bZlSwUwIJS9pW2fpydXOaXZkSPseIyO Njfqtn/y8a1GOMiGPudYKRApJFG96dmXx7t1Dru1cCJ/MO4JAPSItCaC3GzTrecYgt9w FHsQ== X-Gm-Message-State: AOJu0Yw2dThHzSp4LFCrbSYMPnH1aES9+n3P6t0dci6yWfb2ruthEs/4 e/dECm45BvvfbSmOFy32ML+RhbG1flSXKMdQRTzG05e+MFoEuie3H/xA X-Gm-Gg: Acq92OFymJ8FdTNnJ0qbgjfj/j3V2/NMe9fwRf56fuNFZvjJDnK6I3bH+YddMsbPra9 XUEvu4Cpx0GDsj/Fk3NM2yxa2muYyZwINMX0DlXLrHLMzBZ5oSBO3fxp1pNhBznyAqf7UKKYL98 +H2j4N7STjhpHIrPp1OlNTbm7QmOI+8WO880CQmpYkAJBUOGhzoJSUo4yMgXmDQPpsO8QQS5L+m qak+sM5SanVId4BK541ueg2J1RHlkcmxvBJRhQJwZJgn6/pUWva7qB2y6vvD8fk8Agt9w7aB6mh Vp6gLmV4YRgS/CKak53uIDy40yzNQNSx/Ol4Q+SFzyYmz3+eG7ej/XfYP1WqfFf3aaACdoQjYLY OvX75Ht62cwKIAUdxfd4FtWbu7hTMvGAMVPY4maqtA+79Ip3Sn4oYHS4KcntFg3GI7KWjF/pwN+ 16DIP8rhOWdKjGV82jY4Bf0wcXEUKCkQY= X-Received: by 2002:a05:6a00:885:b0:835:45bf:9659 with SMTP id d2e1a72fcca58-8414ae6f95bmr1940255b3a.41.1779348053785; Thu, 21 May 2026 00:20:53 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-841549bf10fsm398079b3a.5.2026.05.21.00.20.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 May 2026 00:20:52 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Fix pg_stat_wal_receiver to show CONNECTING status From: Chao Li In-Reply-To: <1B695040-F544-447C-A6A8-C8BFF7F799D1@gmail.com> Date: Thu, 21 May 2026 15:20:13 +0800 Cc: PostgreSQL-development , Michael Paquier , Xuneng Zhou Content-Transfer-Encoding: quoted-printable Message-Id: References: <1F153E64-B791-42FA-A60A-64813B20B81E@gmail.com> <75CDE990-29D5-4D5C-BFE1-3840F19C0163@gmail.com> <1B695040-F544-447C-A6A8-C8BFF7F799D1@gmail.com> To: Michael Paquier 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 > On May 21, 2026, at 07:06, Chao Li wrote: >=20 >=20 >=20 >> On May 21, 2026, at 04:43, Michael Paquier = wrote: >>=20 >> On Wed, May 20, 2026 at 03:53:38PM +0800, Chao Li wrote: >>> With v2, slot_name, sender_host, sender_port, and conninfo are >>> already left NULL while the receiver is in CONNECTING state. I feel >>> we don't have to show the timestamp fields either. Since the columns >>> are named last_msg_send_time and last_msg_receipt_time, users may >>> naturally interpret them as the last time a message was sent to or >>> received from >>> the primary. If we show the standby server start time in those >>> columns, I am afraid that could be confusing. >>>=20 >>> But I think it might be useful to show the *_lsn and *_tli values in >>> CONNECTING state if they are available. >>=20 >> The original reason why ready_to_display has been introduced is this >> one, where we wanted to have a strict control over the connection >> information across multiple calls of pg_stat_get_wal_receiver(): >> = https://www.postgresql.org/message-id/CAB7nPqQNbHQ7F7wDD_2qvGA_FUW-Leds9HQ= NM6kJnto7RFNhUg@mail.gmail.com >>=20 >> With v2, ready_to_display is still able to do the job it is defined >> for. This does not need to apply on the time fields, so IMO showing >> them to the values they are initialized is not a big deal, and they >> can actually be useful to know even in the early stage of connection >> as they reveal the state of the code. =20 >>=20 >> Note also that the time values could still show up based on their >> initial values at the early connection stage, even after completing >> walrcv_connect() and after ready_to_display is switched to true, so >> it's not like these values are that confusing: we just expose them a >> bit more at an earlier stage of the connection attempt process. As a >> whole v2 is fine, and addresses your issue. >> -- >> Michael >=20 > Thanks for the detailed explanation. >=20 > Now I see that, based on the original discussion you pointed out, as = long as v2 clears conninfo before setting ready_to_display to true, it = is okay to do that earlier while the state is still CONNECTING. On that = point, I=E2=80=99m good with v2. >=20 > I=E2=80=99m still not fully convinced about displaying the *_time = fields, but I don=E2=80=99t have a stronger argument either, so I=E2=80=99= m fine with that. Maybe we can add a brief description in the doc like = the attached diff? >=20 > Overall, v2 looks good to me now. >=20 > Best regards, > -- > Chao Li (Evan) > HighGo Software Co., Ltd. > https://www.highgo.com/ >=20 >=20 >=20 >=20 > I spent more time here, and found that it is still possible to leak = conninfo in the WAL receiver reuse path: * WalRcvWaitForStartPosition() sets the state to WALRCV_WAITING. * Then RequestXLogStreaming() copies raw conninfo into walrcv->conninfo = and sets the state to WALRCV_RESTARTING. * WalRcvWaitForStartPosition() then moves the state to = WALRCV_CONNECTING, but this path does not clear walrcv->conninfo again. The attached nocfbot_test.diff demonstrates the leak. Initially I thought we could also set ready_to_display to false when = setting the state to WALRCV_WAITING in WalRcvWaitForStartPosition(), and = set it back to true when switching back to WALRCV_CONNECTING. However, = that would make the WALRCV_WAITING and WALRCV_RESTARTING states = invisible in pg_stat_wal_receiver. I ended up with a solution that copies the primary connection info to = walrcv->conninfo only when RequestXLogStreaming() is switching to = WALRCV_STARTING. In the WALRCV_WAITING reuse path, the WAL receiver = keeps using the existing wrconn, so it does not need raw conninfo to be = copied into shared memory again. See the attached = nocfbot_walreceiverfuncs.c.diff. With that change, the new test passes. I also ran "make check-world" = successfully. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/