Compared with AOF, redis RDB has higher recovery priority

Time:2021-3-14

Comparison of RDB and AOF

RDB AOF
boot priority low high
volume Small large
Recovery speed fast slow
Data security Loss of data for several times Decision based on Strategy

Persistence mode selection

If the data security requirements are very high, two persistence methods should be used at the same time.

If you can withstand data loss for a certain period of time, you can only use RDB persistence.

It is not recommended to use AOF persistence only, because generating RDB snapshot regularly is very convenient for database backup, and RDB can recover datasets faster than AOF.

Recovery priority of RDB and AOF

If redis uses both RDB and AOF for persistence, redis will give priority to AOF for data recovery.

When starting redis, if it already exists appendonly.aof File, based on appendonly.aof File recovery data; if it does not exist appendonly.aof File, an empty appendonly.aof File and based on this empty appendonly.aof File start.


Due to the above characteristics, special care should be taken when using RDB to recover data and switching to RDB + AOF persistence to avoid data loss.

The correct approach should be as follows:

  1. Stop redis, turn off AOF persistence and keep RDB persistence to prevent it from being generated at startup appendonly.aof Documents;
  2. Copy the RDB file to the data directory and start redis. After starting, redis will use the RDB file to recover the data;
  3. Confirm data recovery and enable AOF persistence by hot modifying the configuration on the command lineconfig set appendonly yes
  4. Wait for redis to write data in memory appendonly.aof At this time, RDB and AOF data are synchronized;
  5. Stop redis, modify the configuration file, and enable AOF persistence and RDB persistence;
  6. After redis is started, data recovery and persistence configuration are completed.

Recommended Today

“Self test” stay up late to summarize 50 Vue knowledge points, all of which will make you God!!!

preface Hello everyone, I’m Lin Sanxin. A lot of things have happened these days (I won’t say what’s specific). These things have scared me to treasure my collection these yearsVue knowledge pointsI took out my notes and tried my best to recall them. Finally, I realized these 50Knowledge points(let’s not be too vulgar. It’s not […]