| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
| Subject: | Re: Fix pg_stat_wal_receiver to show CONNECTING status |
| Date: | 2026-05-19 13:55:39 |
| Message-ID: | agxr29Hsz7FjxzlN@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, May 19, 2026 at 01:55:14PM +0800, Chao Li wrote:
> I also tried restarting the standby server, and the result was the same.
>
> The problem is that pg_stat_wal_receiver is gated by
> WalRcv->ready_to_display, and when the status is CONNECTING,
> WalRcv->ready_to_display is false.
Initially, I was thinking that the walrcv_connect() delay would not be
that important to track in this context, but you are right that this
stands for improvement before the release.
@@ -1474,21 +1474,10 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
- if (pid == 0 || !ready_to_display)
+ /* No WAL receiver, just return a tuple with NULL values */
+ if (pid == 0)
PG_RETURN_NULL();
This suggestion is making the SQL function call feebler, IMO,
impacting the readability around ready_to_display that we want to act
as a gate to the data provided in the view. This flag is important to
check at an early state of the function call, and I don't really want
to change that. A better thing to do would be to split into two steps
how the WAL receiver data is filled between the walrcv_connect() call:
1) Before the call, reset all the connection-related fields because
they are not relevant before the connection to the remote is
completed, set ready_for_display to true to make the connecting state
visible in the view. The connection information does not matter
anyway here: we cannot be sure which point we are connected to until
the connection is fully established.
2) After the call, fill in the connection-related fields.
This means taking twice the WAL receiver spinlock instead of once,
which is not going to matter in practice as the latency of the
connection attempt is much larger than that.
What do you think about the attached, then?
--
Michael
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Improve-pg_stat_wal_receiver-for-CONNECTING-statu.patch | text/plain | 3.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | vignesh C | 2026-05-19 14:00:43 | Re: Proposal: Conflict log history table for Logical Replication |
| Previous Message | Nisha Moond | 2026-05-19 13:38:22 | Re: Improve conflict detection when replication origins are reused |