Configuring Persistence with AOF

1. Understanding AOF Concept

PropertyDetail
FormatAppend-only command log
RecoveryReplay log on restart
DurabilityTunable via fsync policy

2. Enabling AOF

DirectiveValue
appendonly yesEnable

3. Setting AOF Filename

DirectiveDefault
appenddirnameappendonlydir 7.0+
appendfilenameappendonly.aof (base name)

4. Configuring Fsync Policy

PolicyDurabilityPerformance
alwaysPer-write (max safety)Slowest
everysec≤1s loss (recommended)Excellent
noOS decidesFastest

5. Rewriting AOF (BGREWRITEAOF)

CommandDescription
BGREWRITEAOFCompact AOF by writing minimal commands to reconstruct state

6. Auto-Rewrite Configuration

DirectiveDefaultPurpose
auto-aof-rewrite-percentage100Rewrite when AOF doubles vs last rewrite
auto-aof-rewrite-min-size64mbMin size to trigger rewrite

7. Enabling Mixed Persistence

DirectiveDefaultEffect
aof-use-rdb-preamble yesyesAOF starts with RDB snapshot + incremental commands — faster loads

8. Handling AOF Corruption

ToolDescription
redis-check-aof --fixTruncate at corruption point
aof-load-truncated yesLoad partial AOF without manual fix

9. Understanding AOF vs RDB Tradeoffs

AOF

  • Better durability
  • Larger files
  • Slower restart (replay)
  • Continuous fsync overhead

RDB

  • Compact
  • Fast restart
  • Up to N minutes of loss
  • Fork cost on snapshot

10. Managing AOF File Growth

SettingEffect
auto-aof-rewrite-percentageLower → more frequent rewrites
Multi-part AOFManifest + base + incrementals 7.0+

11. Understanding Fsync Performance Impact

PolicyLatency Impact
alwaysPer-write fsync ≈ disk latency
everysecBackground thread, occasional spikes
no-appendfsync-on-rewrite yesSkip fsync during rewrite

12. Recovering from AOF Files

StepAction
1Stop server
2Verify with redis-check-aof
3Place files in appenddirname
4Start; replay happens automatically