Skip to content
gohacks.dev
Databases

UUID Generator

Generate random v4 or time-ordered v7 UUIDs in bulk, and see which one belongs in a database primary key.

Free · No sign-up · Your inputs stay in your browser

Input

Generate UUIDs

Output

Press Generate

v7 starts with the creation time, so new rows land at the end of a B-tree index instead of at random pages; it is the better primary key for MySQL and PostgreSQL. v4 is all random, and the right choice when the ID must not reveal when it was made.

Runs in this browser. Nothing you paste is sent to a server.

v4 or v7?

A v4 UUID is 122 random bits. Inserted as a primary key, each new row lands on a random page of the B-tree index, which causes page splits and a poor cache hit rate as the table grows. A v7 UUID starts with the time it was made, so new rows go to the end of the index the way an auto-increment ID does. RFC 9562 defines both.

The trade-off

v7 reveals when the ID was created, to the millisecond. If that is sensitive, use v4.

In your stack

Laravel's HasUuids trait generates ordered UUIDs by default, and Str::uuid7() is available in recent versions. PostgreSQL has a native uuid type. In MySQL, store UUIDs as BINARY(16) rather than CHAR(36) to more than halve the index size.

Share

Frequently asked questions

Can two generated UUIDs collide?
In practice, no. With 122 random bits for v4, you would need to generate about a billion per second for decades to have a meaningful chance.
Why is v7 better for database keys?
Its values increase over time, so inserts append to the index instead of scattering across it. That keeps writes fast and the index compact.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools