Install PostgreSQL and Connect

Install PostgreSQL, then connect with the built-in psql command-line client β€” the fastest way to run SQL and inspect your database.

Install

bash
# macOS (Homebrew)
brew install postgresql@18 && brew services start postgresql@18

# or run it in Docker (no local install)
docker run -e POSTGRES_PASSWORD=secret -p 5432:5432 postgres:18

Connect with psql

bash
psql -U postgres                              # connect as the postgres user
psql postgresql://user:pass@localhost:5432/mydb   # a connection string

psql meta-commands

Inside psql, backslash commands help you explore (they're psql features, not SQL).

CommandDoes
\llist databases
\c mydbconnect to a database
\dtlist tables
\d productsdescribe a table
\? / \qhelp / quit

Connection basics

Postgres listens on port 5432 by default. A connection needs host, port, database, user, and password β€” often bundled as a URL (postgresql://user:pass@host:5432/db) that apps and tools accept.

Tip: Prefer a GUI? pgAdmin and DBeaver are popular free tools for browsing tables and running queries visually β€” but knowing psql pays off on servers where no GUI is available.
Free preview. Sign in and subscribe to unlock all 809 lessons across 25 courses.
Install PostgreSQL and Connect β€” PostgreSQL | Full Stack Learning Simplified