Introduction Redis Background AOF rewrite (triggered by `BGREWRITEAOF`) creates a new compacted AOF file while the old one is still on disk. If the filesystem does not have enough space for both files simultaneously, the rewrite fails, and Redis may continue appending to an ever-growing AOF file until it eventually runs out of disk entirely.

Symptoms - Redis logs show `Failed opening the temp file for the diskless background rewrite` - `ERR Error writing to file: No space left on device` in Redis log - AOF file size grows continuously without compaction - `INFO persistence` shows `aof_rewrite_in_progress:0` with increasing `aof_current_size` - Disk monitoring shows gradual increase in `/var/lib/redis` partition usage

Common Causes - `auto-aof-rewrite-percentage` and `auto-aof-rewrite-min-size` thresholds not tuned for the workload - AOF file grew significantly between manual rewrite triggers - Disk space was consumed by other processes (logs, backups) leaving insufficient room - `no-appendfsync-on-rewrite` set to `no`, causing slower rewrite that overlaps with more appends - Running Redis on a volume with no monitoring or alerts

Step-by-Step Fix 1. **Check current AOF status and disk usage**: ```bash redis-cli INFO persistence | grep aof df -h /var/lib/redis ls -lh /var/lib/redis/appendonly.aof* ```

  1. 1.Emergency: Free disk space to allow rewrite to proceed:
  2. 2.```bash
  3. 3.# Clean old log files
  4. 4.rm -f /var/log/redis/redis-server.log.5.gz
  5. 5.# Clean old RDB snapshots that are no longer needed
  6. 6.ls -lt /var/lib/redis/dump.rdb.* 2>/dev/null | tail -5
  7. 7.# If running on cloud, expand the volume
  8. 8.`
  9. 9.Manually trigger AOF rewrite after freeing space:
  10. 10.```bash
  11. 11.redis-cli BGREWRITEAOF
  12. 12.# Monitor progress
  13. 13.redis-cli INFO persistence | grep -E "aof_rewrite|aof_current"
  14. 14.`
  15. 15.If rewrite keeps failing, switch to RDB-only persistence temporarily:
  16. 16.```bash
  17. 17.# Save current data
  18. 18.redis-cli BGSAVE

# Disable AOF redis-cli CONFIG SET appendonly no

# Delete the oversized AOF file (after confirming RDB save succeeded) rm /var/lib/redis/appendonly.aof

# Re-enable AOF to create a fresh compacted file redis-cli CONFIG SET appendonly yes ```

  1. 1.Configure automatic AOF rewrite with appropriate thresholds:
  2. 2.```bash
  3. 3.redis-cli CONFIG SET auto-aof-rewrite-percentage 50
  4. 4.redis-cli CONFIG SET auto-aof-rewrite-min-size 64mb
  5. 5.redis-cli CONFIG SET no-appendfsync-on-rewrite yes

# Make persistent echo "auto-aof-rewrite-percentage 50" >> /etc/redis/redis.conf echo "auto-aof-rewrite-min-size 67108864" >> /etc/redis/redis.conf echo "no-appendfsync-on-rewrite yes" >> /etc/redis/redis.conf ```

  1. 1.Set up disk space monitoring:
  2. 2.```bash
  3. 3.# Add to crontab for disk space check
  4. 4.*/5 * * * * df -h /var/lib/redis | awk 'NR==2 {if ($5+0 > 80) print "WARNING: Redis disk at " $5}'
  5. 5.`

Prevention - Set `auto-aof-rewrite-percentage` to 50-100 (rewrite when AOF is 50-100% larger than last rewrite) - Set `auto-aof-rewrite-min-size` to at least 64MB to avoid frequent rewrites - Monitor disk usage with alerting at 70% capacity - Allocate at least 2x the current AOF file size as free space - Use `no-appendfsync-on-rewrite yes` to reduce I/O pressure during rewrite (accepts minor data risk) - Consider Redis 7.0+ multi-part AOF which reduces peak disk usage during rewrite - Run `BGREWRITEAOF` manually during maintenance windows for large datasets