UUID v4 Primary Keys Bloat PostgreSQL Indexes Far More Than BIGINT or UUID v7
A developer benchmarked three primary key types in PostgreSQL 17 by inserting 5 million rows into each table. Random UUID v4 keys produced an index 1.8 times the size of a BIGINT index, with roughly seven times as many pages written. UUID v7 keys, which begin with a timestamp, performed nearly as well as BIGINT. The gap comes from B-tree behavior: sequential keys append to the last page, while random keys scatter writes across the index and leave pages about 30% empty. The author notes that timing figures were noisy on a loaded laptop, while index size and page counts were consistent across rounds. The article recommends BIGINT as a simple default and UUID v7 when IDs are generated across many systems.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in