How to fix ERR Can't handle AOF file: corrupted in Redis
Redis fails to start when the append-only file (AOF) becomes corrupted. Use redis-check-aof to fix the file, but be aware data loss may occur if corruption is in the early part of the file.
Quick fix
Fixes ERR Can't handle AOF file: corrupted
redis-cli shutdown
# or
sudo systemctl stop redis-server- Stop Redis if it's still running
- Back up the corrupted AOF file
- Run redis-check-aof without the --fix flag first
- Attempt to repair the AOF file
redis-cli shutdown# orsudo systemctl stop redis-serverERR Can't handle AOF file: corrupted
What this error means
The Append-Only File (AOF) is Redis's persistence mechanism that logs all write operations. When Redis detects invalid byte sequences or malformed commands in the AOF file at startup, it refuses to load the corrupted data and aborts with this error. This typically happens after unexpected shutdowns, system crashes, or hardware failures during write operations. The corruption makes the file unreadable, preventing Redis from recovering its state.
Typical symptoms
- Redis server fails to start and exits immediately
- Error message mentions "bad file format" or "corrupted"
- Server logs show the redis-check-aof recommendation
- appendonly.aof file exists but cannot be parsed
- Previous data is not loaded after restart attempts
Common causes
- Unexpected system crash or power loss while writing to AOF
- Incomplete write to disk due to insufficient disk space
- Hardware failure or filesystem corruption
- Process killed during AOF rewrite operation
- File system errors during append operations
- Integer overflow on 32-bit systems with large files (4GB+)
How to fix "ERR Can't handle AOF file: corrupted"
If Redis is attempting to restart, stop it completely:
redis-cli shutdown
# or
sudo systemctl stop redis-serverBefore making any repairs, create a backup:
cp /var/lib/redis/appendonly.aof /var/lib/redis/appendonly.aof.backupThis preserves the original file in case you need to analyze it further or try alternative recovery methods.
Diagnose the extent of corruption:
redis-check-aof /var/lib/redis/appendonly.aofThis shows you where the corruption is detected without modifying the file. Note the byte offset reported.
Let redis-check-aof remove the corrupted portion:
redis-check-aof --fix /var/lib/redis/appendonly.aofThe tool will truncate the file at the last valid command, discarding everything after the corruption point. You may lose some recent data depending on when corruption occurred.
Ensure the fixed file is valid:
redis-check-aof /var/lib/redis/appendonly.aof
# Output should show: "AOF appears to be OK"Now start Redis with the repaired AOF:
redis-server
# or
sudo systemctl start redis-serverRedis should now load successfully with data from the last valid point in the AOF.
Advanced notes
If corruption is severe or redis-check-aof cannot fix it, consider: (1) Switching to RDB snapshots if you have a recent backup, (2) Using Redis Sentinel or Cluster for failover to a healthy replica, (3) For large AOF files on 32-bit systems, compile and run redis-check-aof on a 64-bit machine to avoid integer overflow issues. Prevent future corruption by: setting appendfsync to "everysec" or "always", ensuring sufficient disk space, enabling AOF rewrite to keep file size manageable, and using proper shutdown procedures. Redis 8.4+ includes aof-load-corrupt-tail-max-size to automatically repair minor tail corruption.
Frequently asked questions
- What does "ERR Can't handle AOF file: corrupted" mean?
- The Append-Only File (AOF) is Redis's persistence mechanism that logs all write operations. When Redis detects invalid byte sequences or malformed commands in the AOF file at startup, it refuses to load the corrupted data and aborts with this error. This typically happens after unexpected shutdowns, system crashes, or hardware failures during write operations.
- How do I fix "ERR Can't handle AOF file: corrupted"?
- Redis fails to start when the append-only file (AOF) becomes corrupted. Use redis-check-aof to fix the file, but be aware data loss may occur if corruption is in the early part of the file.
- What causes "ERR Can't handle AOF file: corrupted"?
- Unexpected system crash or power loss while writing to AOF Incomplete write to disk due to insufficient disk space Hardware failure or filesystem corruption
- Is the "ERR Can't handle AOF file: corrupted" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐Redis Official Documentation
- ๐Redis Docs - Persistence(Official Docs)
- ๐Redis Docs - Recover a Failed Database(Official Docs)
- ๐ฌRedis DB Group - AOF Corruption Discussion(Stack Overflow)