Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

psql-basics

psql basics

Last reviewed Jun 1, 2026 Content v20260601
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
beginner

This lesson

This lesson teaches psql basics: the SQL patterns, schema habits, and query reasoning you need before advancing in PostgreSQL.

Teams query psql basics on every PostgreSQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply psql basics in contexts like: Modern startups, geospatial apps, and analytics-friendly OLTP systems.

Copy Postgres SQL into psql, local PostgreSQL, or DB Fiddle (PostgreSQL dialect)—use \d and EXPLAIN ANALYZE where lessons show them. The in-browser lab ships later; psql is the practice path now. Also run SELECT version() first to confirm you are on PostgreSQL, not SQLite.

When you can explain the previous lesson's ideas without copying example queries verbatim.

psql is the interactive terminal for PostgreSQL. Meta-commands (backslash) control the client; SQL statements end with ; and talk to the server.

Connection and help

-- From shell:
psql postgresql://user:pass@localhost:5432/practice

-- Inside psql:
\?          -- help on backslash commands
\h SELECT   -- SQL command help
\conninfo

Practice: Run in psql or DB Fiddle (PostgreSQL). Use your practice database from the workflow lesson.

Inspecting objects

\l                    -- databases
\dn                   -- schemas
\dt                   -- tables in search_path
\d+ orders             -- detailed table info
\di                   -- indexes

Running scripts and output

\i /path/to/seed.sql   -- execute file
\o results.txt         -- send query output to file
\x on                  -- expanded display for wide rows
\copy customers TO 'customers.csv' CSV HEADER

\copy is a client-side bulk load/unload—distinct from server COPY which requires server filesystem access.

Important interview questions and answers

  1. Q: \copy vs COPY?
    A: \copy streams through the client; COPY runs on the server with file path permissions on the host.
  2. Q: How to quit psql?
    A: \q or Ctrl+D.

Self-check

  1. Which command shows table column types?
  2. What ends a SQL statement in psql?

Pitfall: Forgetting the semicolon after SQL—psql waits until you terminate the statement.

Interview prep

\d purpose?

Describes table columns, types, defaults, and indexes.

\copy vs COPY?

\copy is client-side; COPY runs on server filesystem.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • \d vs \dt?
  • Quit psql?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump