From: | Tomas Vondra <tomas(at)vondra(dot)me> |
---|---|
To: | Srinath Reddy Sadipiralla <srinath(dot)reddy(at)zohocorp(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: [PATCH] immediately kill psql process if server is not running. |
Date: | 2024-12-07 23:01:40 |
Message-ID: | 81c9c292-a2d8-48a9-879e-f5cd8e43f49d@vondra.me |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 11/8/24 19:42, Srinath Reddy Sadipiralla wrote:
> Hi ,
>
> When a user tries to enter a large query, thinking the server is still
> running, and to their surprise, they discover that the server has
> crashed or stopped, I have observed that the psql process will still be
> running if it is idle even after the server crashes or stops.
>
> solved this using 2 methods:
>
> 1) using a thread (supports --with-readline and --without-readline)
>
> To address this surprise circumstance, I created a patch that creates a
> new thread within the psql process to monitor the File Descriptor of the
> psql process,this thread will monitor for -1 or 0 on psql’s FD using
> select() and recv() functions .If either one of the value is returned
> we terminate the psql process.
>
> 2) Doing the same thing as above but in single process using readline
> callbacks(only supports --with-readline)
>
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?
If you're in an interactive session (which is where this matters), and
you're not running any commands, you're most likely not paying any
attention to it. So if psql terminates, you won't notice that either. It
doesn't change anything.
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?
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.
Overall, I don't quite see why the current behavior is a problem, and/or
why would this be an improvement.
thanks
--
Tomas Vondra
From | Date | Subject | |
---|---|---|---|
Next Message | Илья Жарков | 2024-12-07 23:04:01 | Re: Do not scan index in right table if condition for left join evaluates to false using columns in left table |
Previous Message | Tomas Vondra | 2024-12-07 22:35:25 | Re: Add missing tab completion for ALTER TABLE ADD COLUMN IF NOT EXISTS |