| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
| Cc: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, 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> |
| Subject: | Re: display hot standby state in psql prompt |
| Date: | 2026-01-28 07:35:22 |
| Message-ID: | 1447A553-773E-4743-94AF-EF98F955A2E3@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Jan 27, 2026, at 22:43, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:
>
>
>
> On 27/01/2026 14:51, Fujii Masao wrote:
>> 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?
>
> It seems I reverted too much from the previous patch :)
> Description added again.
>
>>
>>
>> + else
>> + buf[0] = '\0';
>> + }
>> + else
>> + buf[0] = '\0';
>>
>> The second "else + buf[0] = '\0'" does not seem necessary.
>
> Here I was just following the style of other options, like %x
>
> case 'x':
> if (!pset.db)
> buf[0] = '?';
>
> Removed (let me know if I misunderstood your point here)
>
>>
>> + <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.
>
>
> Indentation fixed.
>
>
>>
>>
>> + 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"/>"?
>>
>
> Yes, it's indeed much better. Replaced <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.
>> -----------------
>
> Added as you suggested.
>
> Thanks for the quick review. Much appreciated!
>
> Best, Jim<v9-0001-Add-i-prompt-escape-to-indicate-hot-standby-statu.patch>
V9 looks good to me. And I just did some tests, and all look good.
```
% psql -d evantest
psql (19devel)
Type "help" for help.
evantest=# \set PROMPT1 '%i %/%R%# '
primary evantest=# SHOW in_hot_standby;
in_hot_standby
----------------
off
(1 row)
# at this point, I shutdown the server
primary evantest=# \c
connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Previous connection kept
primary evantest=#
primary evantest=# \set PROMPT1 '%i %# '
primary #
primary # \set PROMPT1 '%i %# '
primary #
primary # ;
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.
>
> exit
```
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | tushar | 2026-01-28 07:34:11 | Re: Non-text mode for pg_dumpall |