Kayavak / Databases / DB·57 PostgreSQL in Depth / Deeper
Deeper · Databases
PostgreSQL in Depth
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
PostgreSQL began as Postgres ("post-Ingres"), Michael Stonebraker's research project at Berkeley from 1986. Its goal was extensibility: users should be able to add their own data types, operators and index methods, which is why PostgreSQL today hosts geographic data (PostGIS), vectors (pgvector) and full-text search as extensions. In 1994–95 Andrew Yu and Jolly Chen added SQL (Postgres95), and in 1996 it became PostgreSQL, developed since by an open community with no single owning company.
Many of its defining behaviours come from early choices. MVCC (from 1999) keeps old versions of rows so readers never block writers, which is also why it needs VACUUM to clean up dead versions. A process per connection, rather than a thread, made it robust and made connection pooling essential. Its reputation for correctness and features made it the most used database among developers in recent surveys.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
In PostgreSQL an UPDATE writes a new version of the row and marks the old one dead. Every transaction sees the versions that were committed when its snapshot was taken, and VACUUM later removes versions nobody can see.
| Question | Answer |
|---|---|
| What is it? | An extensible, open-source relational database with MVCC, a process per connection and a write-ahead log |
| Problem it solves | Correct, feature-rich storage for nearly any workload, without a vendor |
| Parts | Postmaster and backends, shared buffers, WAL, checkpoints, MVCC and visibility, VACUUM and autovacuum, extensions, replication |
| How it works | Writes go to the WAL first, then to pages in memory, flushed at checkpoints; reads see row versions visible to their snapshot |
| Assumptions | Autovacuum keeps up; transactions are short; connections are pooled |
| When they change | A long-running transaction stops VACUUM removing anything newer than it, so tables bloat |
| Where it fails | Thousands of direct connections (processes); very write-heavy single-node workloads |
| Related ideas | Storage engines (ch58); transactions and snapshots (ch59); query plans (ch60) |
What if?
What if a transaction stayed open for a day?
Reason it through, then open
VACUUM can't remove any row version that transaction might still see, so every update and delete in the whole database leaves dead rows that accumulate: tables and indexes bloat, queries slow down, and in the extreme transaction-id wraparound protection forces emergency vacuuming. Idle-in-transaction timeouts and monitoring the oldest transaction age prevent it.
What if PostgreSQL updated rows in place?
Reason it through, then open
Readers would need locks or an undo log to see consistent old values while a writer changed them. Oracle and MySQL's InnoDB do keep old versions in an undo log; PostgreSQL keeps them in the table itself. In-place designs avoid table bloat but pay to reconstruct old versions for long reads; PostgreSQL's design makes reads simple and pushes cost into VACUUM.
Where the boundary is
| Aspect | PostgreSQL's MVCC | Undo-log MVCC (InnoDB, Oracle) |
|---|---|---|
| Old versions live | In the table, as dead tuples | In a separate undo area |
| Cleanup | VACUUM | Purge of undo records |
| Cost shows up as | Bloat if VACUUM falls behind | Long reads reconstructing old versions; undo growth |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Postgres began at Berkeley in 1986 | Historical | Stonebraker's papers; PostgreSQL's history page |
| Readers don't block writers under MVCC | Convention | PostgreSQL's concurrency documentation; explicit locks still can |
| PostgreSQL is among the most used databases | Measured | Developer surveys such as Stack Overflow's (2023–2025) |
Still open
PostgreSQL's process-per-connection model and its storage engine are both subjects of long-running proposals (threads, pluggable table access methods, undo-based storage). Which will land, and when, is open.
What would change your mind? If VACUUM tuning became unnecessary because a new storage engine avoided bloat without other costs, the chapter's maintenance advice would change.
Recall
What does an UPDATE do in PostgreSQL?
Writes a new row version and marks the old one dead; VACUUM removes it later.
Why is a long-running transaction harmful?
VACUUM can't remove versions it might see, so tables bloat across the database.
Why does PostgreSQL need connection pooling?
Each connection is a separate process, so thousands of connections are expensive.
Where did PostgreSQL's extensibility come from?
The original Postgres research goal of user-defined types, operators and indexes.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.