News for hackers. Stuff that matters.
Re:Postgres sequences can skip 32 unexpectedly by stubish on Friday July 16, 2021 @09:32PM (#27862921)
This approach depends on the level of transaction isolation being used, and relying on the higher levels is a foot gun best avoided unless you really know what you are doing and the consequences you are... erm... locking yourself into.
Re:Postgres sequences can skip 32 unexpectedly by Merad on Friday July 16, 2021 @10:54PM (#27863252)
Can you elaborate? The Postgres documentation leads me to believe this would work fine with the default (READ COMMITTED) isolation level. If multiple transactions attempt to modify the same row (incrementing the counter) they're forced to line up until previous updates to that row have been committed or rolled back, hence the risk of lock contention, but each transaction should consistent view of the counter.
Re:Postgres sequences can skip 32 unexpectedly by stubish on Monday July 19, 2021 @02:56AM (#27879952)
Yes, I think you are right. The update locks the row containing the last id, and concurrent transactions block if they too need to grab the lock.

(so performance wise, a sequence is still better due to less locking, but if you can't have holes it seems fine)