A product’s main database runs MySQL 8 on one server, with no replica. It sits on its own data disk, so the data has room to grow.
One afternoon that disk reached 100%. You would expect a crash, a restart, an alert. None came. The database did not crash; it waited. And a database that waits looks, from the outside, exactly like a database that is fine.
Key facts
- The data disk reached 100%: 298 GB, 0 free. The database did not crash and did not restart.
- No row was written for 55 minutes. Requests hung instead of failing.
- 259 GB of the 298 was 2,493 binary log files, kept for 30 days. Nobody read them: the list of replicas was empty.
- Write volume had grown about five times in a month, from about 4 GB to about 20 GB of binary logs a day.
- It was found by accident. No alert fired.
What users saw
The app’s main action never answered. Nothing came back: no error, no success.
Behind it, one write was stuck. Every other write queued behind it. The API showed lock-wait timeouts, but most requests did not fail at all; they hung. No row was written for 55 minutes.
The database’s error log said the same thing again and again: the disk is full while writing the binary log, and the server is waiting for someone to free space. That is a deliberate choice in MySQL. It does not throw away a write it has promised to log. It waits for room, for as long as it takes.
What filled the disk
Not the data. The binary log is MySQL’s record of every change, kept so that a replica can copy it or so that you can replay changes up to a point in time. On this server, it took most of the disk:
| On the data disk | Size |
|---|---|
| Binary logs (2,493 files) | 259 GB |
| Everything else | 39 GB |
| Whole disk | 298 GB |
The logs were kept for 30 days, which is the MySQL 8 default. And nobody read them. The list of replicas was empty. No restore plan needed a month of changes. The disk was full of a record that nobody would ever replay.
Why now
The keep time had not changed. The traffic had. Write volume grew about five times in a month: from about 4 GB of binary logs a day to about 20 GB a day.
Thirty days at the old rate fitted on the disk. Thirty days at the new rate did not. Nobody had touched the setting, and nobody needed to: the setting was in days, and each day had grown heavier.
That is the part worth remembering. A log kept by age grows with your traffic, not with your data. The logs about the data grew with every write.
How it was found
By accident. Someone looking into an unrelated user question noticed that no new row had landed for a while. That was the first sign anyone saw.
No alert fired, and from the point of view of every check we had, nothing was wrong. The process was up. The port answered. The health check was green. The checks asked “is it alive?”, and it was. None of them asked “is it writing?”. We have seen a quiet failure like this before, when a nightly job vanished from the process manager and every check stayed green; this time the database itself was the thing that looked fine.
The fix was not one command
The clean way to free space is MySQL’s own purge statement, which removes old binary logs and updates the server’s list of them. We ran it. It hung too. It waited behind the same stuck writer as everything else.
So the way out was by hand. Only after the 45 oldest log files were removed from the disk did space appear. Then the stuck write finished, the queue behind it drained, and the purge statement ran.
Purging everything older than 7 days freed about 155 GB. The disk went to 50%, with 145 GB free.
The aftershock
Seconds after the purge, the database process was killed for running out of memory, once. It was back 43 seconds later.
We did not prove a cause, so we will not claim one. The lesson we take is plain: when a stuck database starts moving again, expect the pile of waiting work to land all at once. Be watching when it does.
To be honest about where this stands: when this was written, the keep time was still 30 days, and under review. The purge bought time. It did not fix the setting.
Check your own
- Look at what your data disk actually holds. Is it data, or logs about the data? Size the binary log directory on its own.
- Check the keep time, and ask who reads those logs. In MySQL 8 it is
binlog_expire_logs_seconds, and the default is 30 days. No replica and no point-in-time restore plan that needs 30 days means keep fewer days. - Multiply. Daily log growth today times keep days. Compare that with the disk. Do it again when traffic grows: a keep time chosen at the old volume is a time bomb at the new one.
- Alert on two things. Free space on the data disk at two levels, for example 20% and 10%. And “the newest written row is older than N minutes”. The second one catches every “alive but not writing” failure, whatever the cause.
- Know the emergency path before you need it. At 0 free, the purge statement may itself wait. Keep a little reserved space you can release, such as a placeholder file you can delete, so a clean purge can run without touching files by hand.
- After freeing space, watch memory and connections for a few minutes. Everything that waited arrives together.
To see this on your own server, these are the statements to run:
-- Each binary log file and its size SHOW BINARY LOGS; -- How long logs are kept -- (2592000 seconds = 30 days) SHOW VARIABLES LIKE 'binlog_expire_logs_seconds'; -- Who reads them. Empty = nobody. -- (Before 8.0.22: SHOW SLAVE HOSTS;) SHOW REPLICAS; -- Remove logs older than 7 days PURGE BINARY LOGS BEFORE NOW() - INTERVAL 7 DAY;
Common questions
Why did the database not just crash?
With binary logging on, MySQL will not drop a write it has to log. When the disk is full, it waits for space instead of failing the write. The process stays up and the port answers, so it looks alive while nothing is written.
How many days of binary logs should I keep?
As many as a replica or a point-in-time restore actually needs. With neither, keep fewer days. Then multiply your daily log growth by the keep days and compare it with the disk, and do it again when traffic grows.
Melta is free; get it on the App Store or Google Play.