On this page
MVCC, VACUUM & WAL
Prev: postgresql | Up: postgresql | Next: JSONB, Arrays & Advanced Types
Rel: Transactions, ACID & Isolation Levels, Schema Migrations & Reliability
Ref: PostgreSQL โ Routine Vacuuming
Tags: #public #databases #postgresql #mvcc #internals
Contents
- > Tuple Versioning (`xmin` / `xmax`) & MVCC
- > Dead Tuples, Autovacuum & `ANALYZE`
- > WAL, Checkpoints & Replication
Tuple Versioning (xmin / xmax) & MVCC
In PostgreSQL, UPDATE does not overwrite a row in place โ it marks the old tuple with deleting transaction ID xmax and inserts a brand-new tuple version with creating transaction ID xmin. Each transaction sees a consistent snapshot without blocking readers.
Dead Tuples, Autovacuum & ANALYZE
- Once no active snapshot can see an old tuple version, it becomes a dead tuple.
VACUUM/ autovacuum reclaims dead tuple space for reuse (preventing table bloat), updates the visibility map (enabling Index-Only Scans), and freezes oldxminvalues to prevent 32-bit transaction ID wraparound.ANALYZErefreshes column statistics (pg_stats) so the cost-based query planner picks accurate plans.- Avoid long-running
idle in transactionsessions โ they pin the global horizon and prevent autovacuum from cleaning dead tuples.
WAL, Checkpoints & Replication
Every change is appended sequentially to the Write-Ahead Log (WAL) before dirty shared-buffer pages are flushed to disk during checkpoints. WAL powers crash recovery, streaming read replicas, logical replication, and Point-in-Time Recovery (PITR).
Linked from
Related notes
- tuts/databases/postgresql Linked here; links to this page; shared tags: #databases, #postgresql
- tuts/databases/postgresql/jsonb_arrays_and_advanced_types Linked here; links to this page; shared tags: #databases, #postgresql
- tuts/databases/design_patterns/transactions_acid_and_isolation Linked here; links to this page; shared tags: #databases
- tuts/databases/design_patterns/schema_migrations_and_reliability Linked here; shared tags: #databases
- tuts/databases/postgresql/indexes_and_explain_analyze shared tags: #databases, #postgresql
- tuts/databases/postgresql/security_roles_and_rls shared tags: #databases, #postgresql
- tuts/databases/sql/query_execution_lifecycle shared tags: #databases, #internals
- tuts/c/compilation_and_internals shared tags: #internals
- tuts/c/compilation_and_internals/build_pipeline_and_linking shared tags: #internals
- tuts/c/compilation_and_internals/error_handling_and_cleanup shared tags: #internals