# 5.3 The Housekeepers (BGWriter & Checkpointer)

A depot full of millions of busy staff members can get dirty very quickly. Every time a suitcase is updated (Chapter 4), the page on the **[[Chapter 5/5.1 - The Warming Rack (Shared Buffers)|Warming Rack]]** becomes "dirty"—it’s different from the original version in the pantry.
If the room loses power, those warm, modified pages disappear forever. To prevent this, the elephant employs a dedicated staff of **Housekeepers**. The physical law of the database demands that all modified data must eventually be hardened onto magnetic rust.
## 1. The Background Writer (The Stealth Cleaner)
The **Background Writer** is a quiet elephant who tip-toes around the Warming Rack. His entire job is to look for dirty pages that haven't been touched in a while and gently write them back to the **pantry** *before* anyone actually needs the space.
By doing this "just in time," he ensures there are always a few clean, cold spots on the rack ready for the next staff member, so no one has to wait for a "clean-up" in the middle of a lunch rush. He’s the ghost of the tea party!
## 2. The Checkpointer (The Grand Sync)
While the Background Writer is a stealthy cleaner, the **Checkpointer** is the foreman. At regular intervals, he rings a massive bell.
_"Everybody stop! We're doing a total sync!"_
He ensures that *every* change mentioned in the **[[Chapter 4/4.1 - The Pocket Diary (WAL & fsync)|Sequential Diary (WAL)]]** has been successfully written into the pantry shelves in the pantry. Once he is done, he draws a line in the diary and says, "We are safe up to this point." It’s a moment of absolute, terrifying order!
## The Checkpoint Spike
If the Checkpointer is too aggressive, he can clog the conveyor to the pantry, causing everyone else to freeze. This is why tuning the "Housekeeping Schedule" is the most important part of maintaining a happy, lazy elephant.
Without these housekeepers, the elephant would eventually be buried in a mountain of dirty suitcases, and his "Lazy" lifestyle would come to a crashing, data-losing halt. And that would be a very poor tea party indeed.
### Watching the Housekeepers
You can actually see the housekeepers working if you look at their "Shift Log":
```sql
-- Are the cleaners busy today?
SELECT checkpoints_timed, checkpoints_req, buffers_checkpoint, buffers_clean
FROM pg_stat_bgwriter;
```
If **`checkpoints_req`** is high, it means the elephant is filling up his Pocket Diary too fast, and the housekeepers are struggling to keep up. It might be time for a larger diary!
---
[[Chapter 5/5.2 - The Private Desk (Work Mem)|← 5.2 - The Private Desk]] | [[Chapter 5/5.0 - The Hunger of Resources (Memory & Disk)|↑ 5.0 - The Hunger of Resources]] | [[Chapter 5/5.4 - The Great Overflow (Tuple bloat)|5.4 - The Great Overflow →]]