fillfactor is how full an INSERT is allowed to pack a page before it moves on to the next one. tables default to 100: packed solid. set it to 70 or 80 and every page keeps some room in reserve.
the reason is UPDATE. a new row version that fits on the same page can be a HOT update: no new index entries, and the old version can be cleaned up by the next reader instead of waiting for VACUUM. the price is a bigger table.
you know how an UPDATE is an INSERT: the new version of the row has to go somewhere. if the page it's on is full, somewhere is another page, and every index on the table has to learn the new address.
think of a library where every shelf is crammed. a revised edition of a book can't go next to the old one, so it goes on a shelf across the room, and the catalog cards (the index) all need a new entry pointing there. leave a gap at the end of every shelf, and the revision slides in right beside the original. the catalog card for the old one still works: you walk to the shelf and the new edition is right there.
the same 232 rows, at fillfactor 100 and at fillfactor 70, before and after updating every fourth one:
moment =
full100 · fillfactor 100
0
1
2
3
4
·
5 pageslive 31,552 Bdead 7,888 B
room70 · fillfactor 70
0
1
2
3
4
5
6 pageslive 31,552 Bdead 7,888 B
every fourth row updated in both. at 100 the new versions had nowhere to go but a new page. at 70 every one stayed on its own page.
live tuplesold versionsfree spacepage header and line pointers
real output, postgres 18.6 (PGlite 0.5.12) · fillfactor
switch moments. at fillfactor 100 the 58 new versions all land on a fifth page, and the old versions stay behind on the first four. at fillfactor 70 every page had the room, so every new version is on the same page as the one it replaced.
notice the sizes, too. room70 starts at 6 pages for the same rows full100 fits in 4. and after the update, full100 has grown to 5 and room70 hasn't grown at all. still, room70 is the bigger table. fillfactor doesn't save space. it spends space to make updates cheaper.
the figure's tables, as a block you can run. the inserts stop at 70% of each page:
sqldb=lab · session ff
CREATE TABLE full100 (id int PRIMARY KEY, n int, pad text) WITH (fillfactor = 100);CREATE TABLE room70 (id int PRIMARY KEY, n int, pad text) WITH (fillfactor = 70);INSERT INTO full100 SELECT g, 0, repeat('x', 100) FROM generate_series(1, 232) AS g ORDER BY g;INSERT INTO room70 SELECT g, 0, repeat('x', 100) FROM generate_series(1, 232) AS g ORDER BY g;SELECT relname, reloptions, pg_relation_size(oid) / 8192 AS pagesFROM pg_class WHERE relname IN ('full100', 'room70') ORDER BY relname;
output, from postgres 18.6
#1 · CREATE TABLE
#2 · CREATE TABLE
#3 · INSERT 0 232
#4 · INSERT 0 232
#5 · SELECT 2
relnamename
reloptionstext[]
pagesint8
full100
{fillfactor=100}
4
room70
{fillfactor=70}
6
(2 rows)
58 rows to a page at 100, 40 at 70. now update every fourth row, a column no index covers:
sqldb=lab · session ff
continues session ff (1 earlier block run first)
UPDATE full100 SET n = n + 1 WHERE id % 4 = 0;UPDATE room70 SET n = n + 1 WHERE id % 4 = 0;SELECT relname, pg_relation_size(oid) / 8192 AS pagesFROM pg_class WHERE relname IN ('full100', 'room70') ORDER BY relname;
output, from postgres 18.6
#1 · UPDATE 58
#2 · UPDATE 58
#3 · SELECT 2
relnamename
pagesint8
full100
5
room70
6
(2 rows)
predict the output
each table got 58 updates. how many new entries did each primary key get?
sql
SELECT 'full100' AS index, live_items FROM bt_page_stats('full100_pkey', 1)UNION ALLSELECT 'room70', live_items FROM bt_page_stats('room70_pkey', 1);
sqldb=lab · session ff
continues session ff (2 earlier blocks run first)
SELECT 'full100_pkey' AS index, live_items FROM bt_page_stats('full100_pkey', 1)UNION ALLSELECT 'room70_pkey', live_items FROM bt_page_stats('room70_pkey', 1)ORDER BY index;
output, from postgres 18.6
SELECT 2
indextext
live_itemsint4
full100_pkey
290
room70_pkey
232
(2 rows)
full100: new index entries58
full100: HOT updates0
room70: new index entries0
room70: HOT updates58
real output, postgres 18.6 (PGlite 0.5.12) · fillfactor
what 58 updates cost each table: new primary key entries, and updates that stayed on their own page.
232 entries for 232 rows in room70's index. 290 in full100's: one extra per update. and every one of those is an index page write, a WAL record, and later a dead index entry for VACUUM to clean up. on a table with five indexes, multiply by five.
two conditions, and fillfactor only helps with the first:
the new version fits on the same page. that's what the free space is for.
no indexed column changed. if it did, the indexes need a new entry anyway, so there's no point.
you can see which updates made it, tuple by tuple. HEAP_HOT_UPDATED marks an old version whose replacement is on the same page, and HEAP_ONLY_TUPLE marks a version no index points at:
sqldb=lab · session ff
continues session ff (3 earlier blocks run first)
SELECT rel, count(*) FILTER (WHERE (t_infomask2 & 16384) <> 0) AS hot_updated, count(*) FILTER (WHERE (t_infomask2 & 32768) <> 0) AS heap_onlyFROM (SELECT 'full100' AS rel, h.* FROM generate_series(0, 4) AS b, heap_page_items(get_raw_page('full100', b)) AS h UNION ALL SELECT 'room70', h.* FROM generate_series(0, 5) AS b, heap_page_items(get_raw_page('room70', b)) AS h) AS tGROUP BY rel ORDER BY rel;
output, from postgres 18.6
SELECT 2
reltext
hot_updatedint8
heap_onlyint8
full100
0
0
room70
58
58
(2 rows)
all 58 of room70's updates were HOT. none of full100's. here's one of room70's pages up close:
byte 0 headerline pointersroom70 · block 0 · 8 KB · a dot is 16 Btuples, byte 8,192
real output, postgres 18.6 (PGlite 0.5.12) · fillfactor, after the UPDATE
room70's page 0 after the update. pick a slot with a dead version: its t_ctid points at a new version a few slots on, same page. the new versions carry ONLY_TUPLE: no index entry points at them, the chain does.
and there's a second payoff. old versions in a HOT chain can be removed by pruning: the next statement that reads the page and finds it short on space cleans the chain up on the spot, no VACUUM needed. so a page at fillfactor 70 can take update after update, freeing space as fast as it uses it. the details are in HOT updates and pruning.
100, the default, for tables that are only inserted into, or rarely updated: logs, events, history. reserving space there is just waste.
70 to 90 for tables whose rows are updated often, in columns that aren't indexed: counters, statuses, last_seen_at. watch n_tup_hot_upd against n_tup_upd in pg_stat_user_tables and lower it until most updates are HOT.
lower than that rarely pays. every point of fillfactor is a point more table to scan, cache and back up.
indexes have a fillfactor too (b-trees default to 90), for the same reason the other way round: room in a leaf for a new key, so it doesn't have to split. that's page splits.
keylines
fillfactor = how full an INSERT packs a page. tables default to 100, b-tree indexes to 90.
the reserved space lets an UPDATE put the new version on the same page.
same page + no indexed column changed = a HOT update: no new index entries, prunable without vacuum.
it makes the table bigger on purpose. use it on update-heavy tables, not append-only ones.