Re: [PATCH] immediately kill psql process if server is not running.

From: Srinath Reddy <srinath2133(at)gmail(dot)com>
To: Tomas Vondra <tomas(at)vondra(dot)me>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us
Subject: Re: [PATCH] immediately kill psql process if server is not running.
Date: 2025-01-20 05:56:21
Message-ID: CAFC+b6pxJt_bd_zGdb3YCDDJ5K-s8NMEw8ghyA-WkMH3DiriFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Dec 8, 2024 at 4:31 AM Tomas Vondra <tomas(at)vondra(dot)me> wrote:

>
> Yes, it's true that if the connection breaks, the client may not notice
> that until the next command. But why would we want to kill psql in that
> case? How does that improve the user experience?
>
>
Hi Tomas,sorry for the (very!) late reply ,I almost lost hope waiting for
response to my thread :)
sequence of events:
1)server goes down
2)psql still running
3)user is unaware about the server and enters a query
4)boom for a surprise user came to know "server is down"

if in the very 1st place if we killed the psql process if server goes down
,the user won't get the "surprise" that the server has crashed right?,pls
correct me if i am wrong.

Also, it's a long-standing behavior that it the connection closes, I can
> simply repeat the query and it's automatically re-opened.
>
> test=# 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: Succeeded.
> test=# select 1;
> ?column?
> ----------
> 1
> (1 row)
>
> If we just kill psql instead, this won't work anymore. Why would that be
> better?
>

agreed that psql tries to reconnect but only if the user re-tries entering
the query and it's true if the server starts up immediately.

> Also, just killing the process (no matter if by kill or exit), this
> means the usual cleanup doesn't happen. So stuff is not written to
> .psql_history, for example. That doesn't seem great.
>
> I am assuming cleanup means you are talking about the one which happens at
the end of main where PQfinish,fclose which has already been handled in
this patch.
But as you mentioned, history is not written to .psql_history in this patch
,we can save to psql_history by calling finishInput() ,for this I updated
the patch.

Thanks for the feedback Tomas.

Srinath Reddy Sadipiralla,

Attachment Content-Type Size
v2-Kill-psql-process-with-thread-implementation.patch application/octet-stream 7.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kashif Zeeshan 2025-01-20 06:19:49 Re: [PoC] Federated Authn/z with OAUTHBEARER
Previous Message Thomas Munro 2025-01-20 05:33:23 Re: connection establishment versus parallel workers