| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | Jelte Fennema-Nio <postgres(at)jeltef(dot)nl> |
| Subject: | psql single-step mode woes |
| Date: | 2026-07-04 21:47:14 |
| Message-ID: | 7f0278c4-8907-4db7-b1d7-31de89b41c44@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
As I mentioned on the "Don't use the deprecated and insecure PQcancel in
our frontend tools anymore" thread [1], the psql single step mode feels
broken:
Firstly, Ctrl-C doesn't work while you're stopped on the confirmation
prompt:
postgres=# \set SINGLESTEP 1
postgres=# select 1; select 2;
/**(Single step mode: verify
command)******************************************/
select 1;
/**(press return to proceed or enter x and return to
cancel)*******************/
^C^C^C^C^C
Hitting Ctrl-C doesn't get you out of that prompt. It does cause the
query to not execute, but you still need to hit enter. I find that
surprising and I bet most users would agree.
But wait, there's more: The single step mode also doesn't behave very
well if you hit Ctrl-D. If you hit Ctrl-D, it executes all the
subsequent queries without stopping to ask again. It does print the
prompt for each query, but just plows through and executes them anyway.
And that effect persists even beyond the current script you're
executing, if you ran it with "\i <script>". All subsequent scripts you
run with "\i <script>" will also be immediately executed without
confirmation.
Another gripe: That prompt accepts any string except "x" to mean "go
ahead and execute the query". I think that's a bad default. The point of
single-step mode is to carefully examine the query before run, and if
the person types something unexpected, the sane default would be to
prompt again until you type "x" or enter on an empty line.
Furthermore, I think we should only allow single-step mode in an
interactive terminal (i.e. !notty). It doesn't really make sense when
you're reading from a file, for example. Try "cat script.sql | psql
--single-step" to see what happens.
Attached patch addresses all those issues, see commit message for details.
[1]
https://www.postgresql.org/message-id/aea19cfb-0518-4485-b3d8-c7647d450186%40iki.fi
- Heikki
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Improvements-to-psql-single-step-mode.patch | text/x-patch | 13.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Zsolt Parragi | 2026-07-04 21:29:28 | Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore |