Configuring Persistence with AOF
1. Understanding AOF Concept
| Property | Detail |
|---|---|
| Format | Append-only command log |
| Recovery | Replay log on restart |
| Durability | Tunable via fsync policy |
2. Enabling AOF
| Directive | Value |
|---|---|
appendonly yes | Enable |
3. Setting AOF Filename
| Directive | Default |
|---|---|
appenddirname | appendonlydir 7.0+ |
appendfilename | appendonly.aof (base name) |
4. Configuring Fsync Policy
| Policy | Durability | Performance |
|---|---|---|
always | Per-write (max safety) | Slowest |
everysec | ≤1s loss (recommended) | Excellent |
no | OS decides | Fastest |
5. Rewriting AOF (BGREWRITEAOF)
| Command | Description |
|---|---|
BGREWRITEAOF | Compact AOF by writing minimal commands to reconstruct state |
6. Auto-Rewrite Configuration
| Directive | Default | Purpose |
|---|---|---|
auto-aof-rewrite-percentage | 100 | Rewrite when AOF doubles vs last rewrite |
auto-aof-rewrite-min-size | 64mb | Min size to trigger rewrite |
7. Enabling Mixed Persistence
| Directive | Default | Effect |
|---|---|---|
aof-use-rdb-preamble yes | yes | AOF starts with RDB snapshot + incremental commands — faster loads |
8. Handling AOF Corruption
| Tool | Description |
|---|---|
redis-check-aof --fix | Truncate at corruption point |
aof-load-truncated yes | Load partial AOF without manual fix |
9. Understanding AOF vs RDB Tradeoffs
10. Managing AOF File Growth
| Setting | Effect |
|---|---|
auto-aof-rewrite-percentage | Lower → more frequent rewrites |
| Multi-part AOF | Manifest + base + incrementals 7.0+ |
11. Understanding Fsync Performance Impact
| Policy | Latency Impact |
|---|---|
always | Per-write fsync ≈ disk latency |
everysec | Background thread, occasional spikes |
no-appendfsync-on-rewrite yes | Skip fsync during rewrite |
12. Recovering from AOF Files
| Step | Action |
|---|---|
| 1 | Stop server |
| 2 | Verify with redis-check-aof |
| 3 | Place files in appenddirname |
| 4 | Start; replay happens automatically |