Everything, Everywhere
Verified Specification | Standardized Formulas | Instant Precision
Secure & Private (Zero Data Retention) Free Access • No Sign-Up
ANSI SQL-92 / Berenson 1995 PostgreSQL SSI / Cahill 2008 MySQL InnoDB MVCC Zero External Dependencies

Database Concurrency Control: MVCC, Write Skew & Serializable Snapshot Isolation Studio

An architectural deep-dive and real-time simulator for database transaction isolation. Dissect Multi-Version Concurrency Control (PostgreSQL heap tuple xmin/xmax vs MySQL InnoDB undo log roll pointers), simulate Write Skew (A5B) anomalies under Snapshot Isolation vs Serializable Snapshot Isolation (SSI), evaluate Two-Phase Locking (2PL) contention, and synthesize production retry loops.

REPEATABLE READ
Active Isolation Level
VULNERABLE (A5B)
Write Skew Safety
Non-Blocking Readers
MVCC Read Semantics
Lightweight SIREAD
SSI Lock Footprint
SQLSTATE 40001
Serialization Failure Code

Interactive Transaction Schedule Interleaver & Anomaly Simulator

Step through concurrent transactions line-by-line. Observe how Snapshot Isolation (PostgreSQL / MySQL REPEATABLE READ) permits devastating business logic anomalies like Write Skew (A5B), while Serializable Snapshot Isolation (SSI) and Strict Two-Phase Locking (2PL) prevent them.

Step 0 / 8
System Invariant: At least one doctor must remain on call at all times (count(on_call) ≥ 1).

TRANSACTION T1 (Alice)

TRANSACTION T2 (Bob)

PERSISTENT DATABASE STATE

Initialized interleaver. Click 'Step Next Operation' to begin trace...

MVCC Storage Architecture: PostgreSQL Append-Only Heap vs MySQL InnoDB Undo Logs

Relational databases implement Multi-Version Concurrency Control using two radically different storage topologies: PostgreSQL appends new tuple versions into heap pages and manages visibility with xmin/xmax metadata, while MySQL InnoDB mutates records in-place and reconstructs historical snapshots by traversing rollback pointers into undo log segments.

PostgreSQL Tuple Header Anatomy & Visibility Engine

Every row stored in a Postgres 8KB buffer page includes a 23-byte HeapTupleHeaderData. Adjust the active transaction snapshot slider below to inspect which row versions are rendered visible, invisible (uncommitted/aborted), or invisible (dead/superseded).

All TX < xmin are committed and visible.
All TX ≥ xmax are uncommitted and invisible.
In-flight transactions (invisible to snapshot).
Physical Item Pointer t_xmin (Creator) t_xmax (Deleter/Updater) t_infomask Status Tuple Data Visibility Result
VACUUM & Table Bloat: Notice that older versions (e.g. where t_xmax < oldest_xmin) remain physically on disk taking up 8KB page space until VACUUM marks the line pointers as dead. Failure of autovacuum to keep up with high-frequency updates causes severe table and index bloat.

Serializable Snapshot Isolation (SSI) & Serialization Graph Analysis

PostgreSQL Serializable Snapshot Isolation (SSI) dynamically tracks rw-antidependencies (SIREAD locks) across active transactions. When the Direct Serialization Graph (DSG) develops two consecutive rw-antidependency edges (a "dangerous structure"), the engine aborts the pivot transaction with SQLSTATE 40001.

Dangerous Structure Detected: T1 —(rw)→ T2 —(rw)→ T1. Transaction T2 is selected as the victim and aborted with ERROR: could not serialize access due to read/write dependencies among transactions (SQLSTATE 40001).
Dependency Edge Type Formal Mathematical Definition Physical Engine Meaning Impact on Serialization Graph
ww (Write-Write) w1[x] < w2[x] T2 overwrote or updated a tuple version previously written by T1. Must serialize T1 → T2. In standard MVCC, handled by first-committer-wins lock.
wr (Write-Read) w1[x] < r2[x] T2 read a committed tuple version originally written by T1. Must serialize T1 → T2. Standard dependency edge; does not cause non-serializability alone.
rw (rw-Antidependency) r1[x] < w2[x] T1 read a tuple version that was subsequently superseded or deleted by T2. CRITICAL: Indicates T1 should serialize before T2. Two consecutive rw-edges form a dangerous anomaly cycle!

Standard vs Modern Transaction Isolation & Anomaly Matrix

The original ANSI SQL-92 isolation definitions were heavily critiqued by Berenson et al. (1995) for omitting Snapshot Isolation and failing to formalize Write Skew (A5B) and Lost Updates (P4). Modern production databases implement isolation via MVCC rather than simple table locks.

Isolation Level Dirty Read (P1) Non-Repeatable Read (P2) Phantom Read (P3) Lost Update (P4) Read Skew (A5A) Write Skew (A5B) Locking / Concurrency Mechanism
Read Uncommitted Allowed Allowed Allowed Allowed Allowed Allowed Zero read locks. Readers read dirty uncommitted shared memory buffers. (Postgres treats as Read Committed).
Read Committed Prevented Allowed Allowed Allowed Allowed Allowed Statement-level MVCC snapshot refreshed at the start of every single SQL query. Default for PostgreSQL.
Repeatable Read (Snapshot Isolation) Prevented Prevented Prevented* Prevented Prevented Allowed (A5B) Transaction-level MVCC snapshot. In PostgreSQL, blocks phantoms for reads. In MySQL, uses Next-Key Locks. Vulnerable to Write Skew!
Serializable (PostgreSQL SSI) Prevented Prevented Prevented Prevented Prevented Prevented Non-blocking SIREAD locks on tuples/pages/tables. Aborts dangerous rw-antidependency cycles with SQLSTATE 40001.
Serializable (Strict 2PL) Prevented Prevented Prevented Prevented Prevented Prevented Shared (S) and Exclusive (X) locks held until COMMIT. Readers block writers, writers block readers. Zero anomalies, high deadlock risk.

Production Concurrency & Transaction Retry Blueprints

Implementing Serializable Snapshot Isolation (SSI) or explicit locking requires hardened application patterns: handling SQLSTATE 40001 retry loops with jitter, row-level locking ladders, and deadlock prevention.

Sponsored Utility
While You're Here
Sponsored Recommendations
Advertisement