Databases

Choose Redis Persistence: RDB vs AOF

Compare Redis RDB snapshots and AOF logging, then configure the mix that matches how much data you can afford to lose when Redis restarts.

IntermediateLinux server6 min read

Redis RDB vs AOF is the decision that sets how much data disappears when the server restarts. RDB writes a point-in-time snapshot on a schedule, while AOF appends every write to a log you can replay. This guide shows you how to inspect your current settings, configure either mode, and confirm that data actually survives a restart on a Linux VPS.

The short answer: AOF gives you much smaller loss windows, RDB gives you smaller files and faster restarts. Most production servers run both, and Redis uses the AOF on startup when it is enabled.

Before you start

You need:

  • A Linux VPS running Redis 6.x or 7.x. Check with redis-server --version.
  • Root or a sudo-capable user, since you will edit the config file and restart the service.
  • The redis-cli client installed alongside the server.
  • A rough idea of your tolerance for data loss. Losing 60 seconds of writes is fine for a cache; losing 60 seconds of orders is not.

The config file is usually /etc/redis/redis.conf on Ubuntu, Debian, AlmaLinux and Rocky. The data directory is normally /var/lib/redis.

Warning: Changing persistence settings and restarting Redis can drop unsaved keys. Take a copy of the config file first with sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.bak, and test on a staging server before you touch production.

RDB vs AOF in practice

RDB forks the process and writes the whole dataset to dump.rdb when a save rule fires, such as "900 seconds passed and at least 1 key changed". It is compact and quick to load, but a crash between snapshots loses everything written since the last one.

AOF records each write command and replays the log at startup. How much you lose depends on appendfsync:

  • everysec — flush once per second. A crash costs up to about one second of writes. This is the usual choice.
  • always — flush on every write. Safest, but each write pays a disk round trip.
  • no — let the OS decide. Fastest, least predictable.

Since Redis 4, AOF files can start with an RDB preamble (aof-use-rdb-preamble yes), which makes rewrites and restarts faster. Since Redis 7, the AOF is a multi-part file set stored in a directory, so you will see several files rather than one appendonly.aof. Check the Redis documentation for your exact version if the layout looks different.

Check your current persistence settings

Look at what is running before you change anything:

Bash
redis-cli INFO persistence
redis-cli CONFIG GET save
redis-cli CONFIG GET appendonly
redis-cli CONFIG GET appendfsync

In the INFO persistence output, rdb_last_bgsave_status:ok and aof_last_write_status:ok mean the last write succeeded. rdb_changes_since_last_save tells you how many keys are sitting outside the last snapshot.

Configure RDB snapshots only

Open the config file:

Bash
sudo nano /etc/redis/redis.conf

Set the save rules and file options:

save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes

To turn RDB off entirely, use save "". That is only sensible when AOF is enabled or the data is disposable.

Tip: stop-writes-on-bgsave-error yes makes Redis refuse writes when a snapshot fails. That is safer than silently losing snapshots, but it will take your application down if the disk fills. Monitor free space on /var/lib/redis.

Configure AOF only

Replace the save block with an empty one and enable the append-only file:

save ""
appendonly yes
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-use-rdb-preamble yes

appenddirname exists in Redis 7 and later. On Redis 6, leave it out. The rewrite settings keep the log from growing forever: Redis rewrites it once it is 100% larger than the last rewrite and above 64 MB.

Run RDB and AOF together

This is the common production setup. Keep your save rules and set appendonly yes with appendfsync everysec. Redis loads the AOF on startup because it is the more complete record, and the RDB snapshots give you a fast, portable backup file you can copy off the server.

Warning: Both modes fork the process. On a busy instance the fork can briefly use as much memory again as the dataset itself. Make sure the server has headroom, and check that vm.overcommit_memory is set to 1 as the Redis install notes recommend.

Apply the changes

For settings you can change at runtime, use CONFIG SET and then persist them:

Bash
redis-cli CONFIG SET appendonly yes
redis-cli CONFIG SET appendfsync everysec
redis-cli CONFIG REWRITE

CONFIG REWRITE writes the running values back into the config file, so it must be writable by the redis user. If it fails, edit the file by hand and restart instead:

Bash
sudo systemctl restart redis-server

On AlmaLinux and Rocky the unit is usually named redis:

Bash
sudo systemctl restart redis

Check it works

Write a key, restart, and read it back:

Bash
redis-cli SET deploy:test "persisted"
redis-cli DBSIZE
sudo systemctl restart redis-server
redis-cli GET deploy:test

You should get "persisted" back. Then confirm the persistence state:

Bash
redis-cli INFO persistence
redis-cli BGSAVE
redis-cli BGREWRITEAOF

aof_enabled:1, rdb_last_bgsave_status:ok and aof_last_bgrewrite_status:ok mean both paths are healthy. You can also list the files on disk:

Bash
sudo ls -lh /var/lib/redis
sudo ls -lh /var/lib/redis/appendonlydir

Troubleshooting

  • MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk — the last BGSAVE failed. Check free space with df -h and ownership of the data directory with ls -ld /var/lib/redis. Fix the cause rather than disabling the check.
  • The AOF grows to several gigabytes — automatic rewrite is off or the thresholds are too high. Run redis-cli BGREWRITEAOF once, then lower auto-aof-rewrite-percentage and check auto-aof-rewrite-min-size.
  • Redis refuses to start with Bad file format reading the append only file — the AOF was truncated by a crash or a full disk. Back up the files, then run redis-check-aof --fix /var/lib/redis/appendonlydir/appendonly.aof.1.incr.aof (adjust the path for your version) and start again.
  • Everything is gone after a restart — both save and appendonly are disabled, or Redis is writing to a different dir than you expect. Compare redis-cli CONFIG GET dir with the directory you inspected.
  • Writes are slow after switching to appendfsync always — that setting waits for the disk on every command. Move back to everysec unless you genuinely cannot lose a single write, and consider faster storage.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.