Data TutorialsPostgreSQL

How to Exit from PostgreSQL's Command Line Utility (psql)

Posted by AJ Welch

Command line utilities often use different conventions for exiting and it can be difficult to remember the exact command for the utility you’re using. Is it quit? quit()? exit? Ctrl+C? I give up! In this tutorial, we’ll go over the exact commands you can use to quit psql.


psql has a concept of meta-commands which are commands that are evaluated by psql before ever sending anything to the database server. They are denoted by a backslash and then followed by the command and its arguments. The most common way to exit psql is using a meta-command.

Exiting psql Using a Meta-Command

The meta-command for exiting psql is \q. For more information about this and other meta-commands use the meta-command \?.

Exiting psql Using an End-of-Transmission Character

You can also quit psql using the End-of-Transmission (EOT) character. The EOT character signals the end of a file to a program that is waiting for input. In the case of psql, this will cause the program to exit. The EOT character can be sent by typing Ctrl+D.