0%
PostgreSQL Deep Dive: MVCC, Vacuum, Plans, and Replication
Architecture and Storage
Indexes and Query Planning
Concurrency and Schema
HOT Updates and Fillfactor
In PostgreSQL an update is not an in place change. It writes a complete new version of the row and leaves the old one for vacuum, and by default every index on the table gets a new entry pointing at the new version, even indexes on columns that did not change. This write amplification is the single biggest performance difference between Postgres and storage engines that update in place, and it is the reason heap only tuple updates, HOT, exist. This section explains exactly what an ordinary update costs, so the value of HOT and fillfactor is clear.
An update writes a new tuple
When a row is updated, Postgres reads the current version, checks that it is visible and not locked, sets its xmax to the updating transaction, and inserts a new version with the changed values and a fresh xmin. The new version goes wherever there is free space, on the same page if possible, otherwise on another page found through the free space map. The old version stays until vacuum removes it. The full row is written again even if a single integer changed, and large values stored in TOAST are reused by pointer only if they did not change.
Every index gets a new entry
Index entries in Postgres point at a physical location, a page and a line pointer, called the tuple identifier or ctid. When the new version lands at a new location, the old index entries still point at the old version, so each index must receive a new entry for the new location. On a table with eight indexes, an update that changes one non indexed column writes one heap tuple and eight index entries, each possibly causing page splits, plus WAL for all of them. The old entries remain until vacuum removes them, adding to index bloat.
WAL and replication cost
Each heap tuple and index entry written generates WAL, and the first change to each page after a checkpoint writes a full page image. An update that touches nine pages, one heap and eight index leaves, can produce several kilobytes of WAL, much more if it is the first change to those pages since the checkpoint. That WAL is shipped to every standby and archived, so the amplification is paid again in network, replay and storage. A team that sees replication lag rise after adding an index to a heavily updated table is seeing this effect.
Vacuum cost follows
Every dead version and dead index entry must later be cleaned by vacuum, and as the vacuum lesson explained, index vacuuming scans every index in full. So an update heavy table with many indexes produces work at write time, more work at vacuum time, and bloat in between. The combined cost often surprises teams migrating from MySQL InnoDB, which updates rows in place and stores the previous version in an undo log, so secondary indexes change only when their own columns change.
The famous migration story
A widely discussed case is an engineering blog post from a large ride hailing company that moved from Postgres to MySQL in 2016, citing write amplification as a key reason. Their tables had many indexes and frequent updates to non indexed columns, and every update rewrote entries in every index, multiplying WAL and replication traffic. The response from the Postgres community pointed out that HOT updates avoid this for many workloads when tables are designed for them. The case is a useful reminder that the cost is real, and that whether it bites depends on schema and fillfactor choices.
Comparing with in place designs
Engines that update in place keep secondary indexes pointing at a primary key rather than a physical location, so an update of a non indexed column does not touch them. The trade off is that every secondary index lookup must then traverse the primary key index to find the row, an extra lookup per read. Postgres chose physical pointers, which make index reads direct but updates potentially expensive. Neither design is strictly better; they favor different workloads, and HOT narrows the gap for updates.
Which updates are common
In many applications, most updates touch columns that are not indexed: status fields, counters, timestamps like updated_at, JSON payloads, last seen markers. If none of those columns appear in any index, and the new version fits on the same page, the update can be HOT and skip all index work. Knowing which columns change most often, and keeping them out of indexes where possible, is the starting point for update performance in Postgres.
Measuring the cost
pg_stat_user_tables has n_tup_upd, the total number of updated rows, and n_tup_hot_upd, the number of those that were HOT. Their ratio is the HOT ratio. A table with a high update rate and a low HOT ratio is paying full index amplification on most updates. Since version 16, n_tup_newpage_upd also counts updates whose new version went to a different page, which directly shows how many updates failed to be HOT for lack of space on the page rather than because of indexed column changes.
The updated_at trap
A very common pattern is a trigger or ORM feature that sets updated_at on every update, combined with an index on updated_at for queries that find recently changed rows. That index makes every update non HOT, since an indexed column always changes. If the query on recent changes is rare or could use another approach, such as a separate change log table or a BRIN index, removing the B-tree on updated_at can turn most updates on a table into HOT updates and cut write volume dramatically.
Deletes and inserts compared
A delete only sets xmax on the existing version, writing no new tuple and no index entries, though the index entries stay until vacuum. An insert writes one tuple and one entry per index. An update is the worst of both: a new tuple and new entries like an insert, plus an old version and old entries to clean like a delete. That is why update heavy workloads, more than insert heavy ones, are where Postgres tuning effort pays off most.
Index count as a design budget
Because each index adds to the cost of every non HOT update, the number of indexes on a frequently updated table is effectively a budget. Unused indexes, found with idx_scan equal to zero in pg_stat_user_indexes over a long window, cost writes and vacuum time and give nothing back. Duplicate indexes, where one index is a prefix of another, are similar. Auditing indexes on the busiest tables is often the fastest way to cut write volume, independent of HOT.
Bloat in indexes from updates
Dead index entries from non HOT updates are removed by vacuum, but the pages they occupied are not returned to the operating system, and B-tree pages emptied only partially stay sparse. Indexes on update heavy tables therefore tend to grow larger than a fresh build would be. Version 13 added B-tree deduplication, which compresses duplicate keys, and version 14 added bottom up index deletion, which removes dead entries from a leaf page before splitting it when the incoming entry is a non HOT update of an unchanged key. Both reduce, but do not eliminate, index bloat from updates.
Cache pressure from amplification
Every extra index entry written by a non HOT update dirties an index page that must be in shared buffers, so write amplification also means cache amplification. On a table with many indexes on random keys, updates touch leaf pages scattered across each index, pulling them into cache and evicting other data. The background writer and checkpointer then have more dirty pages to flush. HOT updates touch only the heap page, which is often already cached because the row was just read.
An ordinary Postgres update writes a whole new row version and a new entry in every index, plus WAL for all of it, and leaves dead versions for vacuum. Measure the HOT ratio per table, and watch for indexes on columns that change on every update.