DBS101 Unit 7
π DBS101 Unit 7 β Transactions, Concurrency & Recovery
π¦ Before Learning
Before diving into Unit 7, I thought database transactions were just optional features β like wrapping a few queries in a BEGIN and COMMIT. I had no idea how deep the topic went or how critical these concepts were to the reliability and consistency of modern systems.
Terms like ACID, deadlocks, and ARIES recovery sounded technical and intimidating. But now, I see how they form the backbone of trust in systems like banking apps, online shopping, or any service that canβt afford to lose or corrupt data.
π§© Key Takeaways from This Unit
πΉ Lesson 18 β Understanding Transactions & ACID
- A transaction is a sequence of database operations that forms a single, reliable unit of work.
- The famous ACID properties ensure data integrity:
- Atomicity π₯ β All or nothing.
- Consistency β β From one valid state to another.
- Isolation π β Transactions donβt interfere with each other.
- Durability πΎ β Once committed, changes stayβeven after a crash.
π§ͺ Example:
Transferring $50 from account A to B involves updating both balances. If one update happens but the other fails, the system must roll everything back to maintain consistency.
β
πΉ Lesson 19 β Concurrency Control in Action
- Databases allow multiple users to access data at the same time β but this opens the door to conflicts.
- Locking protocols prevent data corruption:
- Shared (S) π β read-only locks
- Exclusive (X) βοΈ β write locks
- Two-Phase Locking (2PL) ensures consistency by:
- Acquiring all locks first (growing phase)
- Releasing them later (shrinking phase)
β οΈ Deadlocks can occur when two transactions wait on each other forever. These are resolved by:
- Detection (using a graph)
- Prevention (wait-die, wound-wait)
π§ Intention locks (IS, IX, SIX) allow scalable locking for different levels (e.g., row vs table).
β
πΉ Lesson 20 β Recovery to the Rescue
Things go wrong. Power fails. Systems crash. And databases must recover.
- Logging (Write-Ahead Logging) records every change before applying it to the database.
- Undo/Redo mechanisms use logs to:
- Roll back failed transactions.
- Reapply committed changes if not yet saved.
π§ ARIES Algorithm (Analysis β Redo β Undo) is a powerful recovery method used in real-world DBMSs.
π Checkpoints reduce the work needed during recovery.
π‘ Fuzzy checkpoints allow updates during checkpointing without blocking users.
πΎ Even main-memory databases have optimized recovery to survive crashes by syncing periodically to disk.
β
π‘ What I Learned and Why It Matters
β
Transactions are more than just SQL wrappersβtheyβre safety nets that ensure trust in digital systems.
β
Concurrency isnβt chaos when you have locks, schedules, and serializability.
β
Recovery isnβt just a backup β itβs a smart, rule-based self-healing process.
β
The database knows how to recover from crashes better than I expected β and thatβs comforting.
π¬ Without these systems in place, a crash could destroy hours of user work. Thatβs not acceptable β and now I understand how databases prevent that.
π Personal Growth & Reflection
Before Unit 7, I assumed databases were like black boxes β they magically stored and retrieved data. But now I see them as complex, resilient machines built with layers of safeguards.
Learning about ACID, deadlocks, locking protocols, and ARIES gave me a new appreciation for how much engineering goes into making things look simple to the user.
Knowing this makes me feel more confident β not just in writing queries, but in designing reliable systems that handle real-world failures gracefully.
π οΈ Including My Work from Class
β Lesson 18 β Transactions
- Practiced PostgreSQL transactions with
BEGIN,COMMIT,ROLLBACK. - Simulated fund transfers using ACID principles.
β Lesson 19 β Concurrency
- Used shared/exclusive locks in examples.
- Simulated deadlocks and resolved them using waits-for graphs.
- Explored 2PL, intention locks, and granularity management.
β Lesson 20 β Recovery
- Wrote and analyzed log entries (
<Ti, Xj, old, new>). - Applied ARIES-style redo/undo manually in exercises.
- Understood checkpoints, crash recovery, and WAL.
π Das Ende (The End)
Unit 7 has taught me that databases are not just about storing data β theyβre about protecting it, recovering it, and managing it under pressure. And thatβs what makes them powerful.