Overview
Write amplification is physical bytes written divided by logical bytes changed. In PostgreSQL, one UPDATE writes a new heap tuple (mvcc), a new entry in every index on the table unless it qualifies as a HOT (heap-only tuple) update, and WAL records for each modification. Count it when a table takes heavy updates, since each extra index and every WAL record multiplies disk I/O.
Rules
- Drop unused indexes and use partial indexes. Each index multiplies the cost of every non-HOT write (secondary-index).
- A HOT update needs no indexed column to change and free space on the same page. Avoid updating indexed columns needlessly, and lower
fillfactoron update-heavy tables to leave room. - vacuum reclaims dead tuples but adds its own I/O and WAL.
- Move cold rows out of hot tables (hot-cold-storage).
- On SSDs high write amplification consumes flash endurance faster. LSM-tree engines (RocksDB, Cassandra) amplify mainly through compaction, which rewrites sorted runs.
Related
- write-ahead-log: every change is logged before it is applied.
- btree-index: each index adds writes.
- secondary-index: the write cost of indexing.
- vacuum: reclaims space at an I/O cost.
- hot-cold-storage: shrinks the hot working set.
- postgres: storage tuning.