psql single-step mode woes
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t252986psql -h localhost -U postgresBuilt from patchset v1 (message #1), August 10, 2026 at 06:11 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t252986_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t252986_1 && git checkout t252986_1Patchset v1 (message #1) is on t252986_1
As I mentioned on the "Don't use the deprecated and insecure PQcancel in
our frontend tools anymore" thread [1]/messages/by-id/aea19cfb-0518-4485-b3d8-c7647d450186@iki.fi, 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]: /messages/by-id/aea19cfb-0518-4485-b3d8-c7647d450186@iki.fi
/messages/by-id/aea19cfb-0518-4485-b3d8-c7647d450186@iki.fi
- Heikki
On Sat, 4 Jul 2026 at 23:47, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
Attached patch addresses all those issues, see commit message for details.
I tried out the patch and overall I like all of the improvements. The
only suggestion would be to make the "ask again" prompt different from
the original ask prompt. For example:
unknown command '<what the user typed instead>': press return to
proceed or enter x and return to cancel
That way it's clear to the user what they did wrong