Transactions, MVCC & Locking
Cheat sheet · https://pcornel.dk/topic.php?topic=6089
Answer
Transactions group statements into all-or-nothing units; MVCC keeps row versions so readers don't block writers; locks protect concurrent changes.
Remember
Keep transactions short. Long open transactions block cleanup (PG vacuum, MySQL purge) and hold locks. Choose the isolation level deliberately.
First checks
SELECT * FROM pg_stat_activity WHERE state <> 'idle'— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
Commands
SHOW ENGINE INNODB STATUS
Verify in this order
BEGIN → reads (snapshot) and writes (locks) → COMMIT/ROLLBACK → versions cleaned
Where it usually breaks
Common failures include idle transactions retaining old versions/locks, inconsistent object access order, oversized batches, assuming MVCC means no locking, and killing a blocker without understanding rollback cost or why it held the resource.
Transactions, MVCC & Locking verification boundary matrix
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Transaction lifecycle | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Isolation levels / MVCC | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Row/table locks | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Blocking | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6089