a HOT update (heap-only tuple) is an UPDATE that writes the new version on the same page and changes no indexed column. then no index is touched: the index entries keep pointing at the old version's slot, and readers follow the chain from there. and the old versions in that chain can be pruned by any later read of the page, without waiting for VACUUM.
you know how every UPDATE writes a new version? if that new version lands somewhere else, every index on the table needs a new entry pointing at it, and every one of those entries needs cleaning up later. a table with five indexes pays six writes per update. that's the expensive part of postgres's MVCC, and HOT is how it gets out of paying it.
think of a library card catalog (the index) pointing at a shelf position (the line pointer). when a book is replaced by a new edition, you could rewrite the catalog card. or, if there's room on the same shelf, you leave a note in the old spot: "newer edition, two to the right". the catalog never changes, and when the old edition is thrown out, the note stays where the catalog points.
the capture is a real postgres 18.6 server: a table items with an index on id and one on sku, on a page that's nearly full. two updates change qty, which no index covers. one changes sku, which items_sku covers. then another session just reads.
T1
·
T2
·
1
obs
2
UPDATE items SET qty = qty - 1 WHERE id = 1→ UPDATE 1
3
UPDATE items SET qty = qty - 1 WHERE id = 1→ UPDATE 1
4
UPDATE items SET sku = 'B-2' WHERE id = 2→ UPDATE 1
5
SELECT qty FROM items WHERE id = 1→ 8
6
obsVACUUM items
versions in items where id=1
index1 → (0,1)
index
(0,1)
xmin759xmax0
id1
skuA-1
qty10
items_pkey
items_sku
the page as loaded: two small rows and six big ones. 952 bytes free.
step 1/6
real output, a postgres 18.6 server · hot-chain
step through. the first two updates stay on the page and touch no index: the chain grows 1 → 9 → 10, the new versions are heap-only (H), and both indexes still have one entry for row 1. the sku update is on the same page too, and it is not HOT: both indexes get a new entry for row 2. then T2's read prunes the page.
no indexed column changed. "indexed" means any column an index uses: in its key, its INCLUDE list, its expression, or a partial index's WHERE. BRIN indexes don't count pg 16+: they summarize page ranges and don't point at tuples.
the new version fits on the same page. if it doesn't, it goes to another page, and an index entry has to point there.
you can watch both in the browser. lab's accounts table gets an index on owner:
sqldb=lab · session hot
CREATE INDEX accounts_owner ON accounts (owner);UPDATE accounts SET balance = balance + 1 WHERE id = 1;UPDATE accounts SET owner = 'alicia' WHERE id = 2;UPDATE accounts SET owner = owner WHERE id = 3;SELECT lp, t_ctid, (heap_tuple_infomask_flags(t_infomask, t_infomask2)).raw_flagsFROM heap_page_items(get_raw_page('accounts', 0)) ORDER BY lp;
slot 1 says HEAP_HOT_UPDATED and its new version in slot 4 says HEAP_ONLY_TUPLE: balance isn't indexed. slot 2 has neither: changing owner wrote a normal tuple in slot 5, with its own index entry. and slot 3?
predict the output
UPDATE accounts SET owner = owner, on the indexed column, changing nothing. HOT or not?
sql
UPDATE accounts SET owner = owner WHERE id = 3;
the index tells the same story from the other side, and the statistics count it:
sqldb=lab · session hot
continues session hot (1 earlier block run first)
SELECT itemoffset, ctid, data FROM bt_page_items('accounts_owner', 1) ORDER BY itemoffset;SELECT pg_stat_force_next_flush();SELECT n_tup_upd, n_tup_hot_upd, n_tup_newpage_updFROM pg_stat_user_tables WHERE relname = 'accounts';
output, from postgres 18.6
#1 · SELECT 4
itemoffsetint2
ctidtid
datatext
1
(0,1)
0d 61 6c 69 63 65 00 00
2
(0,5)
0f 61 6c 69 63 69 61 00
3
(0,2)
09 62 6f 62 00 00 00 00
4
(0,3)
0d 63 61 72 6f 6c 00 00
(4 rows)
#2 · SELECT 1
pg_stat_force_next_flushvoid
''
(1 row)
#3 · SELECT 1
n_tup_updint8
n_tup_hot_updint8
n_tup_newpage_updint8
3
2
0
(1 row)
four entries for three rows: 'alicia' at (0,5) is the non-HOT update's new entry, and the stale 'bob' at (0,2) stays until VACUUM. 3 updates, 2 HOT, none moved to a new page pg 16+. on a real table, n_tup_hot_upd against n_tup_upd is the number to watch.
an index scan for id = 1 in the capture finds the entry (0,1), an address made of a page and a line pointer. slot 1's tuple is dead to new readers, but it's HEAP_HOT_UPDATED, so the scan follows its t_ctid to slot 9, then slot 10, and checks visibility at each stop. all inside one page, already in memory. a chain never leaves its page: that's what makes it safe to skip the index.
after the three updates, the page was down to 820 bytes free. that's the trigger: any statement that reads a page whose free space has dropped below a tenth of it (or below the fillfactor reserve, whichever is bigger) first tries to prune it, if the page has versions nobody can see anymore. here's the page before and after T2's read, and after the VACUUM at the end:
the page =
byte 0 headerline pointersitems · block 0 · 8 KB · a dot is 16 Btuples, byte 8,192
lower 68free 940 B, unlitupper 1008
lp
ctid
xmin
xmax
t_ctid
id
sku
qty
redirect → lp 10
unused
(0,3)
760
0
(0,3)
3
F-3
0
(0,4)
760
0
(0,4)
4
F-4
0
(0,5)
760
0
(0,5)
5
F-5
0
(0,6)
760
0
(0,6)
6
F-6
0
(0,7)
760
0
(0,7)
7
F-7
0
(0,8)
760
0
(0,8)
8
F-8
0
unused
(0,10)
762
0
(0,10)
1
A-1
8
(0,11)
763
0
(0,11)
2
B-2
10
line pointer 1 is redirect: it points at lp 10, the live end of a HOT chain, so index entries for lp 1 still work.
headerline pointer → tuplefree space, unlitdeadin progresswhat this step changed
real postgres 18.6 output · a native server · traces/hot-chain
VACUUM. it removes the index entries that point at row 2's old version, so that line pointer can be freed too.
switch moments and pick slot 1. after the read, slot 1 is a redirect to slot 10, slot 9 is unused, and slot 2 (row 2's old version, which an index entry still points at) is a dead line pointer. after VACUUM removes those index entries, slot 2 is unused too.
what pruning did, slot by slot:
slot 1, the root of row 1's chain, lost its tuple but became a redirect line pointer to slot 10. it has to stay, because both indexes point at (0,1).
slot 9, a heap-only tuple in the middle of the chain, is gone completely, line pointer and all. no index points at a heap-only tuple, so nothing can be left dangling.
slot 2, row 2's old version, left behind by a non-HOT update, lost its tuple but stays as a dead line pointer: two index entries still point at it, and only VACUUM can remove those. (b-trees have a trick of their own for this kind of churn, bottom-up deletion.)
the surviving tuples were slid together, and free space went from 820 to 940 bytes.
pruning works on one page, while holding it. it never touches an index, which is why it can run in the middle of a SELECT. and in the browser engine, where no other session ever holds a snapshot, it happens on almost every read of a full page (the reference chapter runs into it on bank).
the second condition is the one you can do something about. a packed table has no room on any page, so the first update of a row always moves it. fillfactor leaves room. this capture updates one row a thousand times, each update its own transaction, in three tables of 226 rows: packed at fillfactor 100, at fillfactor 90, and packed with the updated column indexed.
ff100: HOT999
ff100: moved to a new page1
ff90: HOT1,000
ff90: moved to a new page0
idx100: HOT0
idx100: moved to a new page4
log scale
real output, a postgres 18.6 server · hot-fillfactor
a thousand updates of one row, on a log scale. the packed table moves the row once, to a new page, and then stays HOT there. at fillfactor 90 every update is HOT, on the page the row started on. index the updated column and none are: the heap goes from 8 KB to 40 KB and the indexes from 32 KB to 56 KB.
the same experiment, in the browser:
sqldb=lab · session ff
CREATE TABLE ff100 (id int PRIMARY KEY, hits int NOT NULL);CREATE TABLE ff90 (id int PRIMARY KEY, hits int NOT NULL) WITH (fillfactor = 90);CREATE TABLE idx100 (id int PRIMARY KEY, hits int NOT NULL);CREATE INDEX idx100_hits ON idx100 (hits);INSERT INTO ff100 SELECT g, 0 FROM generate_series(1, 226) AS g ORDER BY g;INSERT INTO ff90 SELECT g, 0 FROM generate_series(1, 226) AS g ORDER BY g;INSERT INTO idx100 SELECT g, 0 FROM generate_series(1, 226) AS g ORDER BY g;CREATE PROCEDURE bump(t regclass, n int) LANGUAGE plpgsql AS $$BEGIN FOR i IN 1..n LOOP EXECUTE format('UPDATE %s SET hits = hits + 1 WHERE id = 1', t); COMMIT; END LOOP;END $$;CALL bump('ff100', 1000);CALL bump('ff90', 1000);CALL bump('idx100', 1000);SELECT pg_stat_force_next_flush();SELECT relname, n_tup_hot_upd AS hot, n_tup_newpage_upd AS new_page, pg_relation_size(relid) AS heap_bytes, pg_indexes_size(relid) AS index_bytesFROM pg_stat_user_tables WHERE relname IN ('ff100', 'ff90', 'idx100') ORDER BY relname;
output, from postgres 18.6
#1 · CREATE TABLE
#2 · CREATE TABLE
#3 · CREATE TABLE
#4 · CREATE INDEX
#5 · INSERT 0 226
#6 · INSERT 0 226
#7 · INSERT 0 226
#8 · CREATE PROCEDURE
#9 · CALL
#10 · CALL
#11 · CALL
#12 · SELECT 1
pg_stat_force_next_flushvoid
''
(1 row)
#13 · SELECT 3
relnamename
hotint8
new_pageint8
heap_bytesint8
index_bytesint8
ff100
999
1
16384
16384
ff90
1000
0
16384
16384
idx100
0
4
40960
57344
(3 rows)
ff90 started a page bigger (16 KB against 8 KB for the same rows) and never grew. ff100 grew by exactly that one page, the first time the row had to move, and then pruning kept it at that size for 999 more updates. idx100 never had a HOT update: the heap grew to 40 KB because every update left a dead line pointer behind, which only VACUUM can free, so pages ran out of line pointers one after another (4 moves), and the indexes grew with it. fillfactor can't help a column that's indexed.
keylines
HOT = same page + no indexed column changed. then no index is touched.
"changed" means a different value: SET col = col on an indexed column is still HOT.
index scans follow the chain inside the page, from the slot the index points at.
pruning: a read of a nearly full page removes dead versions; the chain root becomes a redirect.
fillfactor leaves room for HOT. indexing the updated column rules it out.