Re: display hot standby state in psql prompt

Jim Jones <jim.jones@uni-muenster.de>

From: Jim Jones <jim.jones@uni-muenster.de>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: Srinath Reddy Sadipiralla <srinath2133@gmail.com>, Greg Sabino Mullane <htamfids@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Nathan Bossart <nathandbossart@gmail.com>
Date: 2025-10-24T20:31:41Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. psql: Add %i prompt escape to indicate hot standby status.

  2. Mark search_path as GUC_REPORT

Attachments


On 24/10/2025 18:13, Jim Jones wrote:
> 
> On 24/10/2025 17:21, Fujii Masao wrote:
>> + const char *hs = PQparameterStatus(pset.db, "in_hot_standby");
>> + const char *ro = PQparameterStatus(pset.db, "default_transaction_read_only");
>>
>> When either hs or ro is NULL, the displayed status can be incorrect.
>> For example, connecting to a standby server running PostgreSQL 10
>> incorrectly shows "read/write". In such cases, wouldn't it be clearer
>> to display something like "unknown", similar to how the "Hot Standby"
>> column in \conninfo reports "unknown"?
> 
> Oh, it didn't occur to me to test this edge case. Thanks for the hint!
> 
> Would this be what you have in mind?
> 
> if (!hs || !ro)
>     strlcpy(buf, "unknown", sizeof(buf));
> else if ((hs && strcmp(hs, "on") == 0) ||
>     (ro && strcmp(ro, "on") == 0))
> 	strlcpy(buf, "read-only", sizeof(buf));
> else
>     strlcpy(buf, "read/write", sizeof(buf));
> 

I just realised I forgot to attach the patch. Sorry about that!
PFA v4.

Best, Jim