PostgreSQL

PostgreSQL is an open-source relational database known for reliability, standards compliance, and depth of features. It stores data in tables, enforces integrity with constraints, guarantees ACID transactions, and extends far beyond plain SQL with JSONB, full-text search, and a huge extension ecosystem.

Originating as POSTGRES at UC Berkeley in 1986 and gaining SQL in 1996, "Postgres" has grown into arguably the most advanced open-source database, often the best default for a new app. It scales from a laptop to large production systems and underpins platforms like Supabase, Neon, and AWS RDS. When in doubt, it's hard to go wrong starting here.

TL;DR

Quick Example

A transaction shows the ACID guarantee — both updates commit together, or neither does:

Core Concepts

💡 NULL means unknown, not zero or empty. Compare with IS NULL, never = NULL.

Architecture in brief

A postmaster process listens for connections and forks a backend process per connection (which is why pooling matters). Backends share memory (shared buffers, WAL buffers, lock tables); changes are written to the WAL before data files, and autovacuum reclaims space from dead row versions in the background.

Deployment Options

Indexing & Performance

See Database Indexing and Query Optimization.

Extensions & JSONB

PostgreSQL's extensibility is a major differentiator:

Security

Comparison

See MySQL, MongoDB, and SQLite.

Best Practices

Common Mistakes

Comparing to NULL with =

No connection pooling

Over-indexing

FAQ

PostgreSQL or MySQL?

PostgreSQL is the stronger default for complex queries, JSON, extensions, and strict correctness. MySQL is a fine choice for simpler, read-heavy web apps or where your hosting/team already favors it. For greenfield projects, many teams default to Postgres.

What is MVCC?

Multi-Version Concurrency Control keeps multiple versions of a row so readers see a consistent snapshot without blocking writers, and writers don't block readers. It's why Postgres handles concurrent load well — at the cost of needing vacuum to clean up old row versions.

Do I really need a connection pool?

For any real web app, yes. Postgres allocates a process per connection, so hundreds of direct connections exhaust memory and max_connections. A pooler (PgBouncer) lets many clients share a small set of backend connections.

Should I store JSON or use normalized tables?

Use normalized tables for relational, queried-on data; use JSONB for genuinely variable or document-shaped fields. Postgres lets you mix both and index JSONB, so you don't have to choose one globally.

How do I scale PostgreSQL?

Vertically first (bigger instance), then read replicas for read-heavy load, a cache (Redis) for hot reads, and Citus or partitioning for very large datasets. Serverless options (Neon, Aurora Serverless) change the operational model.

PostgreSQL Deep Dives

Related Topics

References