Advanced Topic 35 of 51 Databases
Recovery and Logging
Write-ahead logs restoring state after failure.
How it works
Databases recover from crashes using a write-ahead log: every change is recorded in a sequential log and flushed to disk before the data pages are modified or the transaction commits. After a failure, recovery algorithms such as ARIES analyze the log, redo committed work that did not reach disk and undo uncommitted work. Checkpoints limit how much log must be replayed. Backups plus archived logs allow point-in-time recovery.
Step-by-step walkthrough
- A change is first written to the write-ahead log.
- Only then is the commit acknowledged.
- Data pages are flushed to disk later.
- After a crash the log is replayed to redo committed work.
- Uncommitted changes are undone.
Where it is used
Every serious database uses logging to deliver durability and atomicity, and replication systems ship the log to replicas.
Common pitfall
Disabling fsync or using volatile caches risks data loss on power failure. Log files that fill the disk can halt the database. Backups that were never tested may not restore. Plan retention, monitor replication lag and practice restore drills. Remember that logical dumps and physical backups have different recovery speeds and guarantees.
Where it fits in the course
Recovery and Logging is topic 35 of 51 in Databases, rated Advanced. It follows Common Table Expressions. The next topic is Database Partitioning.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Recovery and Logging?
Where do people use Recovery and Logging?
What is the most common mistake with Recovery and Logging?
What should I learn before this topic?
How can I practice it?
Is Recovery and Logging hard to learn?
How long does it take to learn Recovery and Logging?
Which topics are related to Recovery and Logging?
What should I study after Recovery and Logging?
Related topics
- Common Table Expressions (Databases)
- Database Partitioning (Databases)
- Window Functions (Databases)
- Replication (Databases)
- Logging Pipelines (DevOps & Tooling)
- Security Auditing and Logging (Security & Cryptography)
- Disaster Recovery (DevOps & Tooling)