3 ms·
Is my conclusion correct that this implies sequence increments are run outside of the transaction?
by stingraycharles 12y ago
Is my conclusion correct that this implies sequence increments are run outside of the transaction?
- thu 12y agoYes indeed.
- jexus2 12y agoYes: http://www.postgresql.org/docs/9.4/static/functions-sequence.html http://www.postgresql.org/docs/9.4/static/functions-sequence... > Important: To avoid blocking concurrent transactions that obtain numbers from the same sequence, a nextval operation is never rolled back; that is, once a value has been fetched it is considered used, even if the transaction that did the nextval later aborts. This means that aborted transactions might leave unused "holes" in the sequence of assigned values.
- sirclueless 12y agoSequences in Postgres are updated even if a transaction is rolled back. It's pretty easy to see why that's important, especially when dealing with concurrent transactions. You can't give out the same number to multiple transactions without causing a bunch of unique constraint violations. And you can't retroactively decrease a sequence number without affecting all the other transactions currently executing. You could in theory go back and plug in the gaps in a sequence, but it's more important to guarantee that a single thread of execution will always see increasing numbers than it is to guarantee that all numbers will eventually be handed out to a successful transaction.