Debugging: MISCONF Redis is configured to save RDB snapshots

Sometimes Redis will throw out error:

    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.

Override Error in Redis Configuration

Using redis-cli, you can stop it trying to save the snapshot:

config set stop-writes-on-bgsave-error no

This is a quick workaround, but if you care about the data you are using it for, you should check to make sure why BGSAVE failed in first place.

This gives a temporary fix to the problem. However, it is a horrible way to over look this error, since what this option does is stop redis from notifying that writes have been stopped and to move on without writing the data in a snapshot. This is simply ignoring this error.

Save Redis on Low Memory

There might be errors during the bgsave process due to low memory.

This error occurs because of BGSAVE being failed. During BGSAVE,  Redis forks a child process to save the data on disk. Although exact reason for failure of BGSAVE can be checked from logs (usually at /var/log/redis/redis-server.log on linux machines) but a lot of the times BGSAVE fails because the fork can't allocate memory. Many times the fork fails to allocate memory  (although the machine has enough RAM available) because of a conflicting optimization by the OS.

As can be read from Redis FAQ:

Background saving is failing with a fork() error under Linux even if I've a lot of free RAM!
Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits. In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages. A page will be duplicated only when it changes in the child or in the parent. Since in theory all the pages may change while the child process is saving, Linux can't tell in advance how much memory the child will take, so if the overcommit_memory setting is set to zero fork will fail unless there is as much free RAM as required to really duplicate all the parent memory pages, with the result that if you have a Redis dataset of 3 GB and just 2 GB of free memory it will fail.
Setting overcommit_memory to 1 tells Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.
# echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
# sysctl vm.overcommit_memory=1

Redis doesn't need as much memory as the OS thinks it does to write to disk, so may pre-emptively fail the fork.

Sakuragawa Asaba

Sakuragawa Asaba

A designer and photographer. Yet interested in cloud and opensource solutions.