Hacker News new | ask | show | jobs
by wrs 1026 days ago
Many databases including PostgreSQL have a second reason “serial” sequences may have missing numbers. It’s too inefficient to write to the disk every time you get a new value from the sequence, so sequence transactions use up a batch of consecutive values, not just one. The set of values in the batch is then maintained in memory. If (when) the database crashes, the leftovers can’t be restored to the sequence (since there’s no finer-grained log of them). So on average the sequence will permanently skip half of the batch size on each crash.