11, 11 chapters
transactions and isolation
everything.transactions
transactions and isolation
ACID, the anomalies, the isolation levels, and what postgres really gives you at each one.
- 11.01ACID, honestlyatomicity, consistency, isolation, durability. what each letter promises, and what it quietly doesn't.
- 11.02BEGIN, COMMIT and ROLLBACKautocommit, savepoints, idle in transaction, and the aborted transaction that ignores everything you type.
- 11.03the anomaly cataloguedirty reads, non-repeatable reads, phantoms, lost updates, read skew and write skew. each one in two sessions.
- 11.04isolation levels: the standard vs postgresREAD UNCOMMITTED is READ COMMITTED, REPEATABLE READ is snapshot isolation. the table the standard doesn't show you.
- 11.05READ COMMITTED, up closea new snapshot per statement, and the UPDATE that re-checks a row after waiting for it.
- 11.06lost updatesread, modify, write, and one change vanishes. four fixes, compared on a real postgres.
- 11.07SELECT ... FOR UPDATE and SKIP LOCKEDrow locks you ask for, NOWAIT, and a job queue that ten workers can drain without fighting.
- 11.08write skew and SERIALIZABLEtwo engineers go off call at once. snapshot isolation allows it, SERIALIZABLE doesn't.
- 11.09retrying serialization failuresSQLSTATE 40001 is not a bug, it's a request. the retry loop your app needs, and where it goes.
- 11.10deadlockstwo transfers in opposite directions, a cycle, and the transaction postgres kills. lock ordering as the fix.
- 11.11advisory lockslocks on numbers you make up. a mutex for cron jobs, and the session-level one that outlives your transaction.