patternsqlMinor
May postgresql's uuid_generate_v1() conflict when we change the computer date/time?
Viewed 0 times
postgresqlthemaydatetimecomputerwhenchangeconflictuuid_generate_v1
Problem
According to postgresql uuid-ossp documentation
https://www.postgresql.org/docs/9.4/static/uuid-ossp.html
On a distributed database scenario where we have hundreds of databases generating records with UUID keys and syncing back to a central database.
Suppose we detect a machine has a wrong date/time in the future and we change it back to the correct date/time. May it generate a conflicted UUID key on this particular machine?
One scenario is the summer time / daylight savings.
uuid_generate_v1() is based on Mac address + timestamp:https://www.postgresql.org/docs/9.4/static/uuid-ossp.html
On a distributed database scenario where we have hundreds of databases generating records with UUID keys and syncing back to a central database.
Suppose we detect a machine has a wrong date/time in the future and we change it back to the correct date/time. May it generate a conflicted UUID key on this particular machine?
One scenario is the summer time / daylight savings.
Solution
There is no reason, that I know of to use
"One scenario is the summer time / daylight savings." -- no, it is not. Everything should be stored as UTC. Time always goes forwards. – Philᵀᴹ
Even if your display time is set to DST, (or something like CSTCDT), the underlying storage mechanism should be UTC.
That said, though everything should be stored as UTC, it's not always that way. There are exceptions, like with XP, or Windows 7, you may see some kind of abnormality, especially if you permit the other OS to modify the RTC.
And, there is always the problem of leap seconds if you really want to nitpick, when some kernels or daemons will roll back the second and it's basically up to them to see if they support this. Linux-proper and OSX does, Android does not afaik humorous NDT on Leap seconds
For reference, the spec details the process of generating a UUID v1 time-based UUID, 4.2 Algorithms for Creating a Time-Based UUID.
uuid_generate_v1() over uuid_generate_v4(). That said, Philᵀᴹ is largely correct when he says"One scenario is the summer time / daylight savings." -- no, it is not. Everything should be stored as UTC. Time always goes forwards. – Philᵀᴹ
Even if your display time is set to DST, (or something like CSTCDT), the underlying storage mechanism should be UTC.
That said, though everything should be stored as UTC, it's not always that way. There are exceptions, like with XP, or Windows 7, you may see some kind of abnormality, especially if you permit the other OS to modify the RTC.
And, there is always the problem of leap seconds if you really want to nitpick, when some kernels or daemons will roll back the second and it's basically up to them to see if they support this. Linux-proper and OSX does, Android does not afaik humorous NDT on Leap seconds
- For more info about leap seconds
- For more info about RTC/system clocks in linux
For reference, the spec details the process of generating a UUID v1 time-based UUID, 4.2 Algorithms for Creating a Time-Based UUID.
Context
StackExchange Database Administrators Q#174823, answer score: 2
Revisions (0)
No revisions yet.