Database architecture
READ COMMITTED
PostgreSQL takes a fresh statement snapshot. Source-reviewed PostgreSQL/Spring lab or manual procedure, NOT RUN.
Formal Syntax & Structure
java syntaxjava
BEGIN ISOLATION LEVEL READ COMMITTEDWorking Example
Example Snippetjava
# Two-session PostgreSQL 17 experiment — NOT RUNStart from fresh V1 data. Open two psql sessions, A and B, on the same disposable database. Set `statement_timeout='5s'` and `lock_timeout='2s'` in both. No timing sleeps are required: execute the steps in the exact listed order.
1. A: `BEGIN ISOLATION LEVEL READ COMMITTED; SELECT stock FROM inventory WHERE sku='B1';` predicts 5.2. B: `BEGIN; UPDATE inventory SET stock=4 WHERE sku='B1'; COMMIT;`3. A: same SELECT predicts 4; COMMIT.4. Reset stock to 5 in autocommit. Repeat steps 1–3 with A using REPEATABLE READ; A's second SELECT predicts 5. PostgreSQL takes the snapshot at the first non-transaction-control statement, not merely BEGIN.5. Reset again. A and B each BEGIN ISOLATION LEVEL SERIALIZABLE; each SELECT sum(stock) FROM inventory; A updates B1 to 4; B updates B2 to 7; A commits, then B commits (or one statement/commit may fail earlier). Expect one transaction to abort with 40001; do not assume a particular victim. Check that exactly one change committed. Roll back any failed transaction.6. Reset again. A begins, changes B1 to 4, and rolls back. A fresh session SELECT predicts 5. Test stale version separately: update with WHERE version=0, increment version; repeat with version=0 and expect UPDATE 0. Roll back test changes.
These are predictions, not measured PostgreSQL behavior. Close both sessions. Never perform this experiment against shared or production data.