How to exit from PostgreSQL command line utility: psql

こ雲淡風輕ζ 提交于 2019-11-27 09:55:31

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
Kaarel

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

Try:

  • 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
Lukasz Szozda

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.

For Linux command line \q + enter.

Quiting with Ctrl + D also is works

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

This is POSTGRESQL - running on CentOS7 , kindly note i have exited from PSQL with \q , then i am still within the bash Shell for PostgreSQL , which i again Logout with - logout .... terminal output below ---- -bash-4.2$ quit -bash: quit: command not found -bash-4.2$ exit logout There are stopped jobs. -bash-4.2$ logout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!