Re: display hot standby state in psql prompt

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>, Greg Sabino Mullane <htamfids(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Subject: Re: display hot standby state in psql prompt
Date: 2025-10-24 20:31:41
Message-ID: cd2b5819-a21e-403c-8427-66f950613707@uni-muenster.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
v4-0001-Add-i-prompt-escape-to-indicate-server-read-only-.patch text/x-patch 3.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2025-10-24 20:32:54 Re: use SIMD in GetPrivateRefCountEntry()
Previous Message Gregory Smith 2025-10-24 20:22:29 Re: PG18 GIN parallel index build crash - invalid memory alloc request size