Re: display hot standby state in psql prompt

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: Andreas Karlsson <andreas(at)proxel(dot)se>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, 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>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: display hot standby state in psql prompt
Date: 2026-01-27 13:51:01
Message-ID: CAHGQGwGoLh=GpcoxiQ8MbHLzEuBHaGk8E6Cmott1ngYssZev2Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 27, 2026 at 5:36 PM Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:
>
>
>
> On 27/01/2026 04:46, Fujii Masao wrote:
> > Yeah, I'm fine with switching back to the original proposal.
>
> PFA v8 containing the original proposal.
>
> It now only checks in_hot_standby to determine if the current state of
> the connected server is "primary" or "standby".
>
> psql (19devel)
> Type "help" for help.
>
> postgres=# \set PROMPT1 '[%i] # '
> [standby] # SHOW in_hot_standby;
> in_hot_standby
> ----------------
> on
> (1 row)
>
> [standby] # SELECT pg_promote();
> pg_promote
> ------------
> t
> (1 row)
>
> [primary] # SHOW in_hot_standby;
> in_hot_standby
> ----------------
> off
> (1 row)
>
> [primary] #
>
> The documentation was updated accordingly.

Thanks for updating the patch!

It looks like the short description for %i is missing from the header comment
at the top of get_prompt(). Could you add that?

In the patch, nothing is shown when connected to PostgreSQL 13 or older
(i.e., versions that do not report in_hot_standby). Would it be better to
show "?", similar to what %S does?

+ else
+ buf[0] = '\0';
+ }
+ else
+ buf[0] = '\0';

The second "else + buf[0] = '\0'" does not seem necessary.

+ <listitem>
+ <para>
+ Indicates whether the server is in hot standby mode.

The indentation style for "<para>" and its contents seems to differ from
the surrounding prompt option descriptions. For consistency, it might be
better to match the existing style used nearby.

+ The value is shown as <literal>standby</literal> if the
server reports
+ <literal>in_hot_standby</literal> as <literal>on</literal>,

Would it be better to replace "<literal>in_hot_standby</literal>" with
"<xref linkend="guc-in-hot-standby"/>"?

As with %S, it would be helpful to explicitly document what is shown when
connected to PostgreSQL 13 or older. For example, something like:

-----------------
Indicates whether the connected server is running in hot standby mode.
The value is shown as <literal>standby</literal> if the server is
currently in hot standby and reports <xref
linkend="guc-in-hot-standby"/> as <literal>on</literal>, and
<literal>primary</literal> otherwise. This is useful when connecting
to multiple servers to quickly determine the role of each connection.
A value of <literal>?</literal> is shown when connected to a server
running <productname>PostgreSQL</productname> 13 or older.
-----------------

Regards,

--
Fujii Masao

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-01-27 14:03:03 Re: meson: Allow disabling static libraries
Previous Message David Rowley 2026-01-27 13:34:26 Re: More speedups for tuple deformation