Thuta Learning
BasicData & Databasesbeginner

psql Command-Line Essentials

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Explain the core ideas behind psql Command-Line Essentials
  • Run the sample SQL or command and verify its output
  • Apply the technique to the Tutorial Platform and production scenarios

Build the mental model

`psql` is PostgreSQL's official interactive terminal. SQL statements end with a semicolon, while backslash meta-commands such as `\l`, `\dt`, and `\d` provide client-side shortcuts. If the prompt changes unexpectedly, an open quote or parenthesis may be waiting; `\r` clears the input buffer.

Connect it to a real scenario

Enter `tutorial_platform` using the container's `psql`. Query the server version, current database, and current user, then inspect the session with `\conninfo`. During later lessons, run saved SQL files with `\i filename.sql`.

Try the working example

bash
docker exec -it pg-tutorial psql -U postgres -d tutorial_platform

SELECT version();
SELECT current_database(), current_user;
\conninfo
\dt
\q
You should see
You see PostgreSQL 18.x, the `tutorial_platform` database, and the `postgres` user.

5-minute try-it

Open meta-command help with `\?` and find commands that list databases, tables, and functions.

One important caution

Do not write `\dt;`; a meta-command is not a SQL statement and needs no semicolon.

PostgreSQL — psqlPostgreSQL Global Development Group

Easy traps

  • Do not write `\dt;`; a meta-command is not a SQL statement and needs no semicolon.
  • Validate sample code on a local or test database with recoverable backups before applying it to production data.

Exercise

Open meta-command help with `\?` and find commands that list databases, tables, and functions.

You'll know it worked when: You see PostgreSQL 18.x, the `tutorial_platform` database, and the `postgres` user.

psql Command-Line Essentials | Thuta Learning