Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How to exit command line utility psql for PostgreSQL?

share|improve this question
38  
Sometimes 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 Nov 16 '12 at 11:35
17  
+1 for googling "psql exit" and getting the answer in like, 0 seconds –  DMac the Destroyer Mar 13 '13 at 4:23
8  
I upvoted just to irritate people like @a_horse_with_no_name –  vlasits Jan 31 at 15:49
17  
The 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 Feb 20 at 14:39
2  
@Kheldar Indeed, it's just bad user interface design (coupled with arrogance). People are insecure about weird things. –  Iain Collins Mar 10 at 20:46

7 Answers 7

up vote 530 down vote accepted

Type \q and then press ENTER to quit psql.

share|improve this answer
5  
simple but useful. Thanks!! –  Hoàng Long May 30 '12 at 8:00
35  
I can't believe I had to google to work that out :-) Thanks. –  Dave Sag Jun 25 '13 at 1:29
1  
This won't work if you are in single user backend mode (--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. –  hobs Nov 7 '13 at 22:10
1  
yes, very simple solution. I guessed \quite, \exit but none of them worked, finally got solution after googeling. Thanks :) –  Log1c ツ May 15 at 10:28
2  
I was going to upvote @DaveSag - but then I thought, why can we not use "quit" or "exit" like a normal sql program? –  nycynik Jun 19 at 21:53

And for all kinds of similar questions: Use \? in psql for help.

Or read about psql meta commands in the excellent manual.

share|improve this answer
2  
Though this isn't a direct answer, this is quite helpful! Thanks :D –  JAnderton Jul 24 '13 at 7:49

Ctrl+D is what I usually use to exit psql console.

share|improve this answer
    
Thanks, very useful short key. –  App Work Aug 26 '12 at 7:14
6  
This works on almost all prompts, people! –  beardtree Jun 28 '13 at 17:27

Using Ctrl+D or typing logout directly in the terminal works too

share|improve this answer
    
logout doesn't work for me, but CTR+D works fine. –  Kheldar Feb 20 at 14:41

I use Ctrl + Z but I think that's specific to linux.

share|improve this answer
1  
AFAIK It will send your process to background on terminal. –  Log1c ツ May 15 at 10:29
1  
ctrl-z is bg, it does not quit. –  nycynik Jun 20 at 5:00

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
share|improve this answer
    
That's usually what I do too –  Jehan Jul 18 at 22:44

I learned that I could include \q in a batch .sql file, so I could have psql quit earlier from an \i operation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.