Re: display hot standby state in psql prompt

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>, 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: 2025-10-30 10:28:53
Message-ID: 034DCAEE-5F5F-4F32-A83C-6F4BB6765CA8@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 30, 2025, at 17:20, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:
>
> Hi Chao
>
> On 30/10/2025 08:51, Chao Li wrote:
>> I did a quick test, and found a problem. I shutdown the server, and “\c” reconnecting failed, but psql still show “read/write”, which seems wrong:
>>
>> "read/write"\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
>
> I can see that a "read/write" prompt in this case sounds misleading, but
> I am not entirely sure it is a problem. The message says "Previous
> connection kept", which might suggest that the previous parameter values
> are cached? See %p:
>
> postgres=# \set PROMPT1 '[%p] # '
> [1268754] # \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
> [1268754] #
>

Okay, if you consider that is not a problem. 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”?

Without setting PROMIT1, the prompt will become “!?>”.
```
evantest=# 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.
!?>
```

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-10-30 10:31:42 Re: Fix incorrect const qualification for tbm_add_tuples() and itemptr_to_uint64()
Previous Message Ajin Cherian 2025-10-30 10:18:31 Re: Improve pg_sync_replication_slots() to wait for primary to advance