[PATCH] print help from psql when user tries to run pg_restore, pg_dump etc
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:t41622psql -h localhost -U postgresBuilt from patchset v1 (message #1), October 23, 2026 at 01:18 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 t41622_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 t41622_1 && git checkout t41622_1Patchset v1 (message #1) is on t41622_1
New users frequently attempt to run PostgreSQL's command line utilities
from the psql prompt.
They tend to be confused when this appears to do absolutely nothing:
psql=> pg_restore
psql->
since they're generally not going to semicolon-terminate the command either.
The attached patch detects common command names when they appear first on a
new input line prints a help message. If the buffer is empty a more
detailed message is printed and the input is swallowed. Otherwise, much
like how we handle "help" etc,
a short message is printed and the input is still added to the buffer.
psql=> pg_restore
"pg_restore" is a command line utility program.
Use it from the system terminal or command prompt not from psql.
psql=>
psql=> select 1
psql-> pg_restore
"pg_restore" is a command-line utility program not a psql command. See
"help".
psql->
Wording advice would be welcome.
I'd be tempted to backpatch this, since it's one of the things I see users
confused by most often now - right up there with pg_hba.conf issues,
forgetting a semicolon in psql, etc.
--
Craig Ringer http://www.2ndQuadrant.com/
2ndQuadrant - PostgreSQL Solutions for the Enterprise
Hello Craig,
New users frequently attempt to run PostgreSQL's command line utilities
from the psql prompt.
Alas, that is true.
I also have the reverse, i.e. SQL commands fed to bash, which does not
like it much.
They tend to be confused when this appears to do absolutely nothing:
psql=> pg_restore
psql->since they're generally not going to semicolon-terminate the command either.
The attached patch detects common command names when they appear first on a
new input line prints a help message. If the buffer is empty a more
detailed message is printed and the input is swallowed. Otherwise, much
like how we handle "help" etc,
a short message is printed and the input is still added to the buffer.psql=> pg_restore
"pg_restore" is a command line utility program.
Use it from the system terminal or command prompt not from psql.
… prompt, not from psql. (added comma?)
psql=>
psql=> select 1
psql-> pg_restore
"pg_restore" is a command-line utility program not a psql command. See
"help".
psql->Wording advice would be welcome.
I'd be tempted to backpatch this, since it's one of the things I see users
confused by most often now - right up there with pg_hba.conf issues,
forgetting a semicolon in psql, etc.
I doubt that backpathing is reasonable.
Are we that sure that there is no legitimate reason to enter such lines on
psql, eg:
psql=> SELECT '
psql'> pg_whatever ...'
psql-> ...
Although I can confirm that the problem exists, I'm unsure about whether
psql should fix it. What are the opinions around?
--
Fabien.