MySQL Binary Log Disk Growth & Retention Review Prompt
Diagnose runaway binary-log disk usage and design a safe retention, purge, and format strategy without breaking replication or PITR.
- Target user
- DBAs and SREs managing binlog retention, replication, and point-in-time recovery
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior MySQL/MariaDB DBA who manages binary logging for replication and point-in-time recovery. You understand the binary log (ROW vs STATEMENT vs MIXED formats), binlog_expire_logs_seconds / expire_logs_days, sync_binlog, GTID vs file-and-position, the difference between PURGE BINARY LOGS and rm on disk, and why a lagging replica or an orphaned replication slot pins logs and fills the disk. I will provide: - Disk usage and location of the binlog directory (`du -sh`, `df -h`, log_bin_basename): [PASTE] - `SHOW BINARY LOGS;` output and total size: [PASTE] - Relevant settings from `SHOW GLOBAL VARIABLES` (log_bin, binlog_format, binlog_expire_logs_seconds, expire_logs_days, sync_binlog, max_binlog_size, binlog_row_image): [PASTE] - Replica status: for each replica `SHOW REPLICA STATUS` (or SHOW SLAVE STATUS) Seconds_Behind_Source and the file/position it is reading; and `SHOW PROCESSLIST` on the source for Binlog Dump threads: [PASTE] - Whether point-in-time recovery / downstream CDC (Debezium, Maxwell) consumes these logs: [DESCRIBE] Work through this: 1. **Establish why logs are accumulating.** Distinguish the three causes: (a) retention set too long, (b) a lagging or dead replica / CDC consumer holding the read position on an old file, (c) write volume genuinely high. Use the replica read positions vs `SHOW BINARY LOGS` to prove which. 2. **Never delete a log a consumer still needs.** Before any purge, confirm the oldest file every replica and CDC client is still reading; explain why `rm` on disk corrupts the index and breaks replication, and that `PURGE BINARY LOGS TO/BEFORE` is the only safe path. 3. **Right-size retention.** Recommend binlog_expire_logs_seconds against the real recovery window and the slowest consumer's lag budget — long enough for PITR and replica catch-up, not indefinite. 4. **Reduce write volume where safe.** Assess binlog_row_image=minimal, and whether any noisy tables can be excluded; note the replication/CDC trade-offs of each. 5. **Check durability.** Explain sync_binlog=1 (crash-safe, slower) vs 0/N and how it interacts with innodb_flush_log_at_trx_commit for a true durability guarantee. Output: (a) Root cause with the evidence, (b) An ordered, safe purge plan (verify consumers → PURGE BINARY LOGS BEFORE → confirm), (c) Recommended retention and format settings with before/after, (d) Monitoring to add so the disk never silently fills again. Guardrails: never suggest `rm` or `truncate` on binlog files or the binlog index — always PURGE BINARY LOGS. Confirm every replica and CDC consumer's read position before purging. Do not shorten retention below the point-in-time recovery window without explicit sign-off. Note MariaDB uses expire_logs_days / SHOW SLAVE STATUS while MySQL 8 uses binlog_expire_logs_seconds / SHOW REPLICA STATUS.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Binary-log disk exhaustion is one of the most common ways a healthy MySQL server falls over, and the instinct under pressure — rm the old files to free space — is exactly the action that turns a full disk into a broken replication topology. This prompt front-loads the discipline that prevents that: it forces the model to prove why logs are piling up before touching anything, using the replicas’ actual read positions against SHOW BINARY LOGS rather than guessing.
The structure separates the three genuinely different root causes — over-long retention, a stalled consumer pinning an old file, and legitimately high write volume — because each has a different fix and conflating them makes the problem worse. A dead replica holding position on binlog.000042 cannot be solved by shortening retention; the logs are pinned regardless. By making the diagnosis explicit, the prompt steers toward the correct remedy instead of a purge that either fails or breaks a consumer.
Finally, it keeps the safe path non-negotiable: PURGE BINARY LOGS BEFORE after verifying consumers, never a filesystem delete, and never trimming below the recovery window without sign-off. It also flags the MariaDB-versus-MySQL 8 syntax split (expire_logs_days/SHOW SLAVE STATUS vs binlog_expire_logs_seconds/SHOW REPLICA STATUS) so the generated commands actually run on the server in front of you.
Related prompts
-
MySQL Replication Lag & GTID Debug Prompt
Diagnose replica lag and binlog/GTID replication errors and produce a safe recovery plan.
-
MySQL Errant GTID Transaction Reconciliation Prompt
Detect and safely reconcile errant transactions (GTIDs on a replica the source never had) that block failover or break GTID replication.
-
MySQL Replica Promotion & Failover Runbook Prompt
Produce a step-by-step, safety-checked runbook to promote a replica to primary during planned or emergency failover without split-brain or data loss.
-
MySQL Large-Table Archival & Batch Delete Prompt
Design a chunked archive-and-purge for a huge table that avoids long locks, replication lag, and runaway undo/history growth.
More MySQL prompts & error guides
Browse every MySQL prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.