</>
CodeLearn Pro
Start Learning Free β†’

PostgreSQL

Intermediate

Open source Β· since 1996 Β· Relational + Document

PostgreSQL is the world's most advanced open-source relational database. Full SQL compliance, JSONB, window functions, full-text search, CTEs, extensions, and ACID transactions β€” all in one battle-tested system trusted by Apple, Instagram, Spotify, and Reddit.

ACIDJSONBWindow FunctionsFull-Text SearchExtensionsPostGISLogical Replication
16k+
GitHub Stars
28+
Years Active
1000+
Extensions
32 TB
Max Table Size
Apple Β· Spotify Β· Reddit
Trusted by
PostgreSQL (permissive)
License

Why PostgreSQL

Beyond basic SQL

PostgreSQL gives you features most databases charge enterprise licensing for β€” completely free.

ACID Compliant

Full Atomicity, Consistency, Isolation, Durability. Your data is always in a valid state, even after crashes.

Window Functions

Running totals, rankings, moving averages β€” in pure SQL. No application-level aggregation needed.

JSONB + Indexing

Store semi-structured data with full GIN indexing. Query nested JSON as fast as regular columns.

Full-Text Search

Built-in Google-style text search with ranking, highlighting, and multilingual stemming. No Elasticsearch needed.

Recursive CTEs

Traverse trees, org charts, and graphs directly in SQL using RECURSIVE CTEs. No procedural loops needed.

Extensions

PostGIS for geo, TimescaleDB for time-series, pgvector for AI embeddings β€” PostgreSQL is extensible by design.

Advanced Indexing

B-tree, Hash, GiST, SP-GiST, GIN, BRIN β€” the right index type for every data shape. Partial and expression indexes.

Open Source & Free

PostgreSQL licence is permissive β€” use it in any project, commercial or not, with no restrictions or royalties.

Getting Started

Installation & Setup

🐧 Linux (Ubuntu / Debian)
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo -u postgres psql
🍎 macOS (Homebrew)
brew install postgresql@16
brew services start postgresql@16
psql postgres
πŸͺŸ Windows
# Download installer from postgresql.org/download/windows
# Or use Chocolatey:
choco install postgresql
psql -U postgres
🐳 Docker (fastest)
docker run -d \
  --name postgres \
  -e POSTGRES_PASSWORD=secret \
  -p 5432:5432 \
  postgres:16

docker exec -it postgres psql -U postgres

Recommended GUI clients: pgAdmin 4 (free, web-based), TablePlus (macOS/Windows/Linux), DBeaver (free, cross-platform), Postico (macOS).

Cheat Sheet

Quick Reference

Click any syntax to copy

ConceptSyntax
Create table
CREATE TABLE t (id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL);
Add column
ALTER TABLE t ADD COLUMN col TEXT DEFAULT '';
Add index
CREATE INDEX idx ON t (col);
Add foreign key
col INT REFERENCES other(id) ON DELETE CASCADE;
Create enum type
CREATE TYPE mood AS ENUM ('sad','ok','happy');
Drop table
DROP TABLE IF EXISTS t CASCADE;

Ready to go deeper?

The full tutorial covers DDL, DML, advanced queries, window functions, JSONB, full-text search, transactions, and EXPLAIN ANALYZE β€” with 12 hands-on examples.

The Story of PostgreSQL

Real history, real companies, and an honest look at where PostgreSQLshines and where it doesn't β€” not just a feature list.

πŸ•°οΈ

Where it came from

PostgreSQL traces back to the POSTGRES project at UC Berkeley, led by database pioneer Michael Stonebraker starting in 1986, as a research successor to his earlier Ingres project. It gained SQL support and its current name in the mid-1990s and has been developed as free, open-source software by a global community ever since β€” with no single company controlling its direction.

🏒

How it’s actually used today

PostgreSQL is the primary database behind Instagram, Reddit, Skype and Spotify, chosen specifically for its combination of strict data-correctness guarantees and advanced features like full-text search and JSON support built directly into the database. Many managed cloud database services (Amazon RDS, Supabase, Neon) are built specifically around it.

βš–οΈ

Strengths & trade-offs

PostgreSQL's strict adherence to SQL standards and strong consistency guarantees make it an unusually safe choice for data where correctness really matters, like financial transactions β€” the trade-off is that it can require more careful tuning for extremely high write-throughput workloads than a database purpose-built for that scale, like Cassandra.

🧭

What to learn next

Learning how to design a proper relational schema β€” normalisation, foreign keys, indexes β€” is the natural depth to add after basic queries. From there, pairing PostgreSQL with a back-end framework in Python (Django) or Node.js (via an ORM) is the standard next step toward building a real application.