UUIDv7 or UUIDv4 keys in Postgres: 11M rows, 22x slower

In our PostgreSQL 18 lab, 11 million inserts took 1,526 seconds with UUIDv4 keys, 68 seconds with UUIDv7 and 59 seconds with bigint, because random keys stop fitting in cache.

UUIDv7 keeps the primary key index at 90 percent leaf density versus 65 percent for UUIDv4, and cuts WAL volume by about 27 percent, at 30 bytes of index per row versus 23 for bigint.

Migrating needs one statement on PostgreSQL 18, ALTER COLUMN id SET DEFAULT uuidv7(); keep UUIDv4 only for secrets and small tables, since UUIDv7 reveals creation time.

Read the full post

Read the full post