How to exit from PostgreSQL command line utility: psql

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.


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

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


Use:

  • Ctrl+Z - this sends the TSTP signal (TSTP is short for “terminal stop”)
  • Ctrl+\ - this sends the QUIT signal

For curiosity:

  • Ctrl+D - this sends the 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:
  • 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