Log compaction prevents an ordered change log from growing without bound. A system can create checkpoints, combine operations or retain only the latest relevant record for each key, depending on its recovery model.
Compaction must preserve a validated recovery point before old records are discarded. Incorrect or interrupted compaction can make state unrecoverable, so systems commonly build and verify a new generation before promoting it.
ELI5
Log compaction makes a long record of changes smaller while keeping enough information to restore the correct current state. It can combine older changes into a verified checkpoint or keep only the latest useful record for each item.
For example, if a setting changed from blue to red and then to green, a compacted log may retain the verified green state instead of every intermediate change. The system should build and check the replacement before removing old history so an interruption cannot destroy recovery data.
Why compact a write-ahead log?
Compaction reduces storage and replay time while retaining the information required to reconstruct current state.
Is log compaction the same as deleting old records?
It can remove superseded records only after a verified compacted representation or checkpoint safely preserves required state.

