POSTGRESQL-ESSENTIALS practice question 9 of 15

Which psql command quits the psql interface?

Full set: 71 questions
Answer options
A: \exit
B: \quit Correct answer
C: \q Correct answer
D: All of the above
Correct Answer:
B. \quit; C. \q
Explanation

The psql interactive terminal provides two equivalent meta-commands to terminate the session and return to the command shell. The primary command is \quit, and \q is its documented shortcut. Both commands achieve the same result of quitting the psql program. The choice between them is a matter of user preference for verbosity or brevity.

Why Incorrect

A. \exit: This is not a valid psql meta-command. Users may confuse it with the exit command from shell environments or other database clients like Oracle's SQLPlus.
D. All of the above: This option is incorrect because \exit (Option A) is not a valid command to quit the psql interface.

References

1. PostgreSQL 16 Documentation, psql, Meta-Commands: The official documentation explicitly lists the commands for quitting. It states: \q or \quit "Quits the psql program. In a script file, only execution of that script is terminated." The command \exit is not listed. (Source: PostgreSQL Documentation, Chapter: psql, Section: Meta-Commands).

2. University of California, Berkeley, CS 186 Introduction to Database Systems, Project 0 - Getting Started: University courseware for this foundational database course instructs students on basic psql usage. In the setup guide, it states: "To exit psql, type \q and press enter." This confirms \q as a standard command for this purpose. (Source: UC Berkeley EECS, CS 186, Fall 2023, Project 0).

Scroll to Top