What command or short key can I use to exit the PostgreSQL command line utility psql?
-
8@a_horse_with_no_name: I'm not shocked by the question, but the number of upvotes :) Compare e.g. to How do you quit the Vi editor with single keypress?user272735– user2727352012-07-25 16:04:22 +00:00Commented Jul 25, 2012 at 16:04
-
180Sometimes we need quick and straight forward answer than searching it in the manual to focus on the real problem.In such cases these short questions are really helpful.App Work– App Work2012-11-16 11:35:15 +00:00Commented Nov 16, 2012 at 11:35
-
191The real question is not "are people capable of reading a manual", but "should enterprise software respond to standard exit sequences" like, I don't know, "exit"? Having to read the manual to quit seems seriously counter-intuitive.Kheldar– Kheldar2014-02-20 14:39:53 +00:00Commented Feb 20, 2014 at 14:39
-
24@Kheldar Indeed, it's just bad user interface design (coupled with arrogance). People are insecure about weird things.Iain Collins– Iain Collins2014-03-10 20:46:54 +00:00Commented Mar 10, 2014 at 20:46
-
50more importantly, this post is now the first hit when i google "exit psql"Angel S. Moreno– Angel S. Moreno2014-09-02 04:42:51 +00:00Commented Sep 2, 2014 at 4:42
7 Answers
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.
8 Comments
--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.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
10 Comments
Ctrl+D is what I usually use to exit psql console.
5 Comments
Use:
- Ctrl+Z - this sends the
TSTPsignal (TSTPis short for “terminal stop”) - Ctrl+\ - this sends the
QUITsignal
For curiosity:
- Ctrl+D - this sends the
EOFcharacter.EOFstands 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: - any other character is entered before - try entering some white spaces and then press Ctrl+D, it's not going to exit psql.
- if the user input is not required at all
4 Comments
psql is well documented and is \q\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.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 processquit 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.