Menu

Write-Ahead Log Explained: How a Database Survives a Power Cut
📰

Write-Ahead Log Explained: How a Database Survives a Power Cut

DEV Community: mysql·Dilip V P·11 days ago
#aeYuqpib
#devtomysql#devto#dev#mysql#disk
Long article (991 words) — no AI summary yet.
Reading 0:00
15s threshold

Your database says done. One second later, the power goes out. When the power comes back, the change is still there. This article shows why, with one order and one small note: the write-ahead log.

The video tells the same story in six minutes. This is the written version, with the SQL.

One change, two copies of a page

Alex's pizza arrives, and the rider marks the order delivered:

UPDATE orders SET status = 'delivered' WHERE order_id = 4473 ;

Enter fullscreen mode

Exit fullscreen mode

MySQL stores rows on pages of 16 KB, with a few hundred rows on each one. Say Alex's order is on page 61. MySQL changes that page in memory and marks it dirty. The copy of page 61 on disk still says the order is on the way.

A power cut wipes memory. If nothing else happened, the change would be gone, and the rider would not get paid.

Why not write the whole page?

You'd expect MySQL to write the page to disk before it says done. But the page is 16 KB, and only one word changed.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.