UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
cybertec-postgresql.com
UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
1–10 of 182 posts
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#2Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#3I don't think I've ever seen this mentioned anywhere, but if you need a unique ID for an entity with not a lot of records planned (≤10,000,000), why not use a random int64 with a simple for loop on the application side to catch the occasional collisions? Are there any downsides besides making the application side a tiny bit more complex?
https://www.postgresql.org/docs/current/plpgsql-control-stru...
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#4I don't think I've ever seen this mentioned anywhere, but if you need a unique ID for an entity with not a lot of records planned (≤10,000,000), why not use a random int64 with a simple for loop on the application side to catch the occasional collisions? Are there any downsides besides making the application side a tiny bit more complex?
For your use-case you could use incremental IDs.
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#5Essentially, they observed sizeable performance improvements by using UUID generators that are tweaked to get more sequentia resultsl. It results in better indexes. The articles compares sequences, random UUIDs and 2 kinds of sequentialish UUID generators.
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#6Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#7I don't think I've ever seen this mentioned anywhere, but if you need a unique ID for an entity with not a lot of records planned (≤10,000,000), why not use a random int64 with a simple for loop on the application side to catch the occasional collisions? Are there any downsides besides making the application side a tiny bit more complex?
[1] https://en.wikipedia.org/wiki/Birthday_problem#Probability_t...
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#8I don't think I've ever seen this mentioned anywhere, but if you need a unique ID for an entity with not a lot of records planned (≤10,000,000), why not use a random int64 with a simple for loop on the application side to catch the occasional collisions? Are there any downsides besides making the application side a tiny bit more complex?
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#9I don't think I've ever seen this mentioned anywhere, but if you need a unique ID for an entity with not a lot of records planned (≤10,000,000), why not use a random int64 with a simple for loop on the application side to catch the occasional collisions? Are there any downsides besides making the application side a tiny bit more complex?
That’s the UUID approach, but worse. According to the birthday problem[1], you’re 50% likely to get a collision in 65 bit numbers after about 5 billion insertions. That’s not an awful lot. Replace that with a 128-bit UUID and you’d have to insert 22,000,000,000,000,000,000 rows to get a 50% chance. That’s probably less likely than a cosmic ray flipping a random bit in RAM and corrupting the index that way. [1] https:…
Re: UUID, serial or identity columns for PostgreSQL auto-generated primary keys?
#10So it's good to know that performances are not bad.