What command or short key can I use to exit the PostgreSQL command line utility psql
?
Type \q
and then press ENTER
to quit psql
.
UPDATE: 19-OCT-2018
As of PostgreSQL 11, the keywords "quit
" and "exit
" in the PostgreSQL command-line interface have been included to help make it easier to leave the command-line tool.
Answered 2023-09-21 08:07:16
--single
). Instead use Kaarel's answer (Ctrl-D
). In addition to always working in pgsql it'll work in most your other unix shells (python, mysql, etc). If you always do things the "standard" way in 'nix your brain will be less cluttered with trivia. - anyone My usual key sequence is:
quit()
quit
exit()
exit
q
q()
!q
^C
help
Alt + Tab
google.com
Quit PSQL
\q
I think veterans of the psql command line usually shorten that to just:
\q
Answered 2023-09-21 08:07:16
Ctrl+D is what I usually use to exit psql console.
Answered 2023-09-21 08:07:16
Use:
TSTP
signal (TSTP
is short for “terminal stop”)QUIT
signalFor curiosity:
EOF
character. EOF
stands for "end of file". In this concrete case it exits from the psql subprogram, as the shell is waiting for user input. This should not be 'the way to go' as it is not working if:Answered 2023-09-21 08:07:16
psql
is well documented and is \q
- anyone \q
: "This won't work if you are in single user backend mode (--single). Instead use Kaarel's answer (CtrlD
)". IMHO using CtrlD
is not the way to go either, and I explained why above and offered an alternative. - anyone Ctrl+Z
was the only command that worked for me - I was connected to a database via tunnel which lost the connection - neither \q
nor Ctrl+D
worked, but I could Ctrl+Z
and then kill the suspended process - anyone quit
or exit
or \q
Based on PostgreSQL 11 Beta 1 Released!:
User Experience Enhancements
Another feature that fell into this category was the inability to intuitively quit from the PostgreSQL command-line (psql). There has been numerous recorded complaints of users trying to quit with the quit and exit commands, only to learn that the command to do so was \q.
We have heard your frustrations and have now added the ability to quit the command-line using the keywords quit and exit and hope that quitting a PostgreSQL session is now as enjoyable as using PostgreSQL.
Answered 2023-09-21 08:07:16
\?
or \h
to continue learning 'everything else' imho - anyone I learned that I could include \q in a batch .sql file, so I could have psql quit earlier from an \i operation.
Answered 2023-09-21 08:07:16
Actually, \q
, exit
and CTRL + D
didn't work for me to exit from the psql program.
Ctrl + Shift + D
This worked for me.
My Ubuntu version is 19.04.
Answered 2023-09-21 08:07:16
For Linux command line \q + enter.
Quiting with Ctrl + D also is works
Answered 2023-09-21 08:07:16