Atomicity
All transaction effects become durable together, or none remain after rollback/recovery.
CodeBhavyaReason about interleaved operations, prevent unsafe observations, resolve lock cycles and restore committed state after failure.
BEGINA = A − ₹200B = B + ₹200COMMITAll transaction effects become durable together, or none remain after rollback/recovery.
A correctly written transaction preserves declared constraints and application invariants.
Concurrent execution is controlled so transactions do not observe disallowed intermediate effects.
After commit succeeds, recovery mechanisms preserve the transaction despite later failure.
One transaction finishes before another begins. Simple but restricts concurrency.
Operations overlap while each transaction's own program order remains intact.
If T2 reads a value written by T1, T2 commits only after T1 commits.
Transactions read only committed values, avoiding cascading rollback from dirty dependencies.
No other transaction reads or writes an item written by an uncommitted transaction.
T2 uses T1's new value, but T1 later rolls back.
T1 reads the same row twice and sees a committed update by T2 between reads.
T1 repeats a predicate query and sees inserted, deleted or newly qualifying rows.
Two transactions derive new values from stale reads; the later write erases earlier work.
T2 overwrites a value written by active T1, making rollback unsafe.
Transactions read the same condition, update different rows and jointly violate a constraint.
| Requested / Held | Shared (S) | Exclusive (X) |
|---|---|---|
| Shared (S) | Compatible | Wait |
| Exclusive (X) | Wait | Wait |
Multiple transactions can read the same item when none holds an exclusive lock.
A writer excludes other readers/writers under this simplified compatibility model.
Moving S → X may wait if another shared holder remains and can contribute to deadlock.
Row locks improve concurrency; page/table locks reduce lock-management overhead.
No lock has yet been released.
Basic 2PL acquires no new lock after the first release.
Strict 2PL: hold exclusive locks until commit or rollback. This prevents dirty reads of written items and simplifies recovery. Two-phase locking ensures conflict serializability but can create deadlocks.
| SQL level | Dirty read | Non-repeatable read | Phantom | Typical idea |
|---|---|---|---|---|
| READ UNCOMMITTED | Possible | Possible | Possible | Weakest standard level |
| READ COMMITTED | Prevented | Possible | Possible | Each statement sees committed data |
| REPEATABLE READ | Prevented | Prevented | Standard permits phantoms | Repeated row reads remain stable |
| SERIALIZABLE | Prevented | Prevented | Prevented | Outcome equivalent to serial execution |
Multi-version concurrency control lets readers use appropriate row versions instead of always blocking writers. Visibility rules, isolation semantics and cleanup differ by database product.
T7 changes account A from 500 to 650.
<T7, A, old=500, new=650>Required log information reaches stable storage before the changed data page.
Commit is acknowledged only after required log records are durable.
The changed page may be written later.
Use before-images or inverse information for transactions without a durable commit.
Use after-images for committed work not yet reflected in recovered data pages.
Records recovery metadata so restart need not reason from the beginning of the entire log.
Widely taught recovery approach using WAL, repeating history and compensation log records.
Choose a schedule and step through reads, writes, commits and aborts. Watch values, dependencies and the final diagnosis change.
Build each wait-for graph step by step. A directed cycle means the transactions cannot all proceed without intervention.
Mark this level when you can trace schedules, diagnose cycles and explain recovery decisions.
Saved in this browser only.