Postgres.fm· Nikolay Samokhvalov and Michael Christofides·
Postgres.fm: The Real Cost of UUIDv4 vs UUIDv7 Primary Keys on Postgres 18
UUIDv4 vs UUIDv7
Key Takeaway
On Postgres. fm, Nik and Kirk Wolak compare what a random UUIDv4 primary key actually costs against time-ordered UUIDv7 or int8 keys on Postgres 18, covering index size, WAL and full-page writes, and insert rates once the index outgrows memory.
Why It Matters
When choosing a primary key, weigh insert throughput after the index outgrows memory alongside index size and full-page write overhead, rather than comparing key widths alone.
Technical Breakdown · Distilled from the original source
Key choices and UUID functions in Postgres 18
- The DBLab Forge brief compares three primary-key choices: random UUIDv4, time-ordered UUIDv7, and
int8. The episode first references the brief at 00:00:34. The supplied show notes identify what was compared, but do not include numerical results or rank the three choices. - The episode links to commit
78c5e141e9c1, dated December 11, 2024, which addeduuidv7()to Postgres 18. It also links to the version 18 UUID function documentation foruuidv7()anduuid_extract_timestamp(), and cites RFC 9562 as the standards reference for UUIDv7.
WAL, compression, and I/O measurement
- The discussion separates index size, WAL and full-page writes, and insert throughput after the index outgrows memory. The last condition is explicit in the episode description, so that part of the comparison should not be generalized to a workload whose index still fits in memory.
- The configuration references cover
full_page_writesandwal_compression, withlz4andzstdmentioned in connection with compression. The episode also links to thepg_stat_iostatistics view and thefiotool. The show notes do not specify the compression settings used in the experiment or report I/O measurements.
Source: Postgres.fm· share.transistor.fm
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.