0
0
PostgreSQLquery~5 mins

psql command-line tool basics in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is psql in PostgreSQL?

psql is a command-line tool that lets you interact with a PostgreSQL database by typing commands and queries directly.

Click to reveal answer
beginner
How do you connect to a PostgreSQL database using psql?

Use the command psql -d database_name -U username. This opens a session connected to the specified database as the given user.

Click to reveal answer
beginner
What does the command \q do in psql?

\q quits the psql tool and ends your session.

Click to reveal answer
beginner
How can you list all tables in the current database using psql?

Type \dt to see a list of all tables in the connected database.

Click to reveal answer
beginner
What is the purpose of the command \? in psql?

\? shows help information listing all available psql commands and their descriptions.

Click to reveal answer
Which command exits the psql tool?
Aexit()
B\exit
C\q
Dquit
How do you list all tables in the current database in psql?
A\dt
B\list
C\tables
D\show tables
What does the command psql -d mydb -U user1 do?
AConnects to the database mydb as user1
BCreates a new database named mydb
CDeletes the database mydb
DLists all users in the database
Which command shows help information about psql commands?
A\help
Bhelp()
Cman psql
D\?
If you want to run a SQL query in psql, what must you end the query with?
AA period (.)
BA semicolon (;)
CA comma (,)
DNo special character needed
Explain how to start a psql session to connect to a PostgreSQL database.
Think about the command format to open <code>psql</code> with database and user.
You got /4 concepts.
    List three useful psql meta-commands and what they do.
    Meta-commands start with a backslash \.
    You got /3 concepts.