On this page
Transactions, ACID & Isolation Levels
Prev: Indexing & Storage Engines | Up: design_patterns | Next: Scaling, Partitioning & Sharding
Rel: PostgreSQL MVCC, VACUUM & WAL, SQLite WAL Mode & PRAGMAs
Ref: PostgreSQL — Transaction Isolation
Tags: #public #databases #design-patterns #acid #transactions
Contents
ACID Guarantees
- Atomicity: All statements in a transaction commit together or roll back completely.
- Consistency: Transactions transition the database from one valid constraint-preserving state to another.
- Isolation: Concurrent transactions do not corrupt each other's intermediate state.
- Durability: Committed transactions survive crashes (via Write-Ahead Log / fsync).
Isolation Levels & Read Anomalies
| Isolation Level | Dirty Read | Non-Repeatable Read | Phantom Read | Write Skew |
|---|---|---|---|---|
READ UNCOMMITTED |
Possible | Possible | Possible | Possible |
READ COMMITTED (PG default) |
Prevented | Possible | Possible | Possible |
REPEATABLE READ (Snapshot) |
Prevented | Prevented | Prevented (in PG) | Possible |
SERIALIZABLE |
Prevented | Prevented | Prevented | Prevented |
MVCC vs. Pessimistic Locking
- MVCC (Multi-Version Concurrency Control) keeps row snapshots so readers never block writers and writers never block readers.
- When two transactions must update the same row safely (e.g., inventory deduction), use explicit row locking (
SELECT ... FOR UPDATE) or optimistic concurrency (WHERE version = ?).
Linked from
- tuts/databases/design_patterns
- tuts/databases/design_patterns/indexing_and_storage_engines
- tuts/databases/design_patterns/scaling_partitioning_and_sharding
- tuts/databases/design_patterns/schema_migrations_and_reliability
- tuts/databases/design_patterns/transactions_acid_and_isolation
- tuts/databases/nosql/cap_pacelc_and_consistency
- tuts/databases/postgresql/mvcc_vacuum_and_wal
- tuts/databases/sqlite3/wal_mode_and_pragmas
- tuts/programming/concurrency/synchronization_and_coordination
Related notes
- tuts/databases/design_patterns Linked here; links to this page; shared tags: #databases
- tuts/databases/design_patterns/indexing_and_storage_engines Linked here; links to this page; shared tags: #databases
- tuts/databases/design_patterns/scaling_partitioning_and_sharding Linked here; links to this page; shared tags: #databases
- tuts/databases/postgresql/mvcc_vacuum_and_wal Linked here; links to this page; shared tags: #databases
- tuts/databases/sqlite3/wal_mode_and_pragmas Linked here; links to this page; shared tags: #databases
- tuts/databases/design_patterns/schema_migrations_and_reliability links to this page; shared tags: #databases
- tuts/databases/nosql/cap_pacelc_and_consistency links to this page; shared tags: #databases
- tuts/programming/concurrency/synchronization_and_coordination links to this page
- tuts/databases/mongodb/indexes_replica_sets_and_transactions shared tags: #databases, #transactions
- tuts/databases shared tags: #databases