Skip to main content

Command Palette

Search for a command to run...

Write-Ahead Log

Published
1 min read
Write-Ahead Log

When we read about Databases, we come across ACID properties and how the databases make sure the data stays consistent and durable even when a system fails in between a transaction or right after a transaction. But how does the database make sure that this happens?

Whenever a transaction modifies the database, the changes are first written to a log file on disk before being applied to the database. This logging happens before the changes are made to the data files. It separates the logging of changes from the actual modification of the data.

Write-ahead logging ensures that the changes made by a transaction are durable, even in the event of a system failure or crash. If a failure occurs, the DBMS can use the log to recover the database state by reapplying the changes from the log to the data files.

The transactions where you are updating something in the database will be logged into the log file which means something like a "select" statement won't be logged in it.