Re: display hot standby state in psql prompt

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

From: Jim Jones <jim.jones@uni-muenster.de>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Fujii Masao <masao.fujii@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>, Srinath Reddy Sadipiralla <srinath2133@gmail.com>, Greg Sabino Mullane <htamfids@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-10-30T10:50:50Z
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


On 30/10/2025 11:28, Chao Li wrote:
> How about this?
> 
> ```
> [read/write]select * from test_multi order by category, name;
> 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.
> []
> []
> ```
> 
> After shutting down the server, I ran a random statement in psql, then the prompt became empty, does it suppose to show “_unknown”?

This behaviour is normal -- at least it is how other options behave. See
%p and the newly committed %S:

postgres=# \set PROMPT1 '[%p] # '
[1376487] # \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
[1376487] # SELECT 1;
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.
[] # SELECT 1;
You are currently not connected to a database.
[] #

====

psql (19devel)
Type "help" for help.

postgres=# \set PROMPT1 '[%S] # '
["$user", public] # \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
["$user", public] # SELECT 1;
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.
[] # SELECT 1;
You are currently not connected to a database.
[] #


Best, Jim