PostgreSQL Transaction Isolation, Row Versions, and Deadlock Diagnosis
Intermediate · 45 minutes · 100 points
In this lab you will spin up a PostgreSQL instance inside an Ubuntu container and use two concurrent psql sessions to explore all three standard transaction isolation levels (READ COMMITTED, REPEATABLE READ, SERIALIZABLE). You will inspect internal row versioning fields (xmin/xmax) to understand how MVCC works under the hood, then deliberately reproduce a deadlock between two sessions and diagnose it using pg_locks and the PostgreSQL server log. This is a foundational exercise for any developer or DBA who needs to reason about concurrency, consistency, and performance in PostgreSQL.
What you’ll learn
- Demonstrate how READ COMMITTED, REPEATABLE READ, and SERIALIZABLE isolation levels behave differently when concurrent transactions modify shared rows
- Inspect PostgreSQL MVCC internals by querying xmin and xmax system columns to observe row version lifecycle
- Reproduce a two-session deadlock, capture it from pg_locks, and locate the deadlock error in the PostgreSQL server log
How this lab works
- Start the lab: One click starts a container on your computer with a real terminal: nothing to install by hand, nothing to clean up.
- Work through 3 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work runs each task’s checks in your container and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: A container on your computer, with a real terminal
- Image: ubuntu:22.04
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- Docker Desktop installed and running
Topics: postgresql, transactions, isolation-levels, mvcc, deadlock, pg_locks, concurrency, read-committed, repeatable-read, serializable
Create a free account to start this lab.