pgsql: Improve pg_stat_wal_receiver for CONNECTING status

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve pg_stat_wal_receiver for CONNECTING status
Date: 2026-05-22 19:04:40
Message-ID: E1wQVAm-000gFA-0o@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve pg_stat_wal_receiver for CONNECTING status

Commit a36164e7465 added a CONNECTING status for the WAL receiver, but
pg_stat_wal_receiver returned no information while the connection to the
primary was attempted, limiting the usability of the feature in
high-latency environments where the connection attempt to the primary
could take time.

This commit improves the report of the status by splitting the way the
shared memory state of the WAL receiver is filled before and after the
connection to the primary is attempted with walrcv_connect():
- Before the attempt, reset all the connection fields, switch
ready_to_display to true.
- After the attempt, fill in the connection fields.

This change means two spinlock acquisitions instead of one, but at least
monitoring tools can know about the connection attempt before its
completion, enlarging the usability of the feature. This code path is
taken only once when a WAL receiver is spawned, so the extra acquisition
does not matter performance-wise.

Reported-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Author: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://postgr.es/m/EF91FF76-1E2B-4F3B-9162-290B4DC517FF@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7f469097c72e6f8988024eb9bc1b417bfeb29fd9

Modified Files
--------------
src/backend/replication/walreceiver.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-05-22 23:18:12 pgsql: Avoid exposing WAL receiver raw conninfo during timeline jumps
Previous Message Fujii Masao 2026-05-22 15:27:43 pgsql: Set notice receiver before libpq connection startup completes