Linux – redis: Fixing memory error when saving snapshot to database


I see the following error in redis logs:

[17541] 10 Aug 16:13:21.055 * 1 changes in 900 seconds. Saving…

[17541] 10 Aug 16:13:21.055 # Can't save in background: fork: Cannot
allocate memory [17541]

And error message saying:

> Error running script (call to
> f_1477e1798ff8d1bae3066a94781114c056f9ef08): @user_script:8:
> @user_script: 8: -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.

This looks strange as dump.rdb file seems to be reasonably small ~90Mb. And also I tired to create another file in the same folder, and managed to do it (so disk space is not the issue). Permissions looks good to me:

ubuntu@ip-172-31-39-198:/var/lib/redis$ ls -hla
total 89M
drwxr-xr-x  2 redis redis 4.0K Aug 10 16:23 .
drwxr-xr-x 47 root  root  4.0K Aug 10 15:18 ..
-rw-rw----  1 redis redis  89M Aug 10 15:19 dump.rdb

After some googling I have found this as a solution:
echo 1 > /proc/sys/vm/overcommit_memory sysctl vm.overcommit_memory=1

Which makes no sense to me, as I expected the issue to be solved with redis config…
Could you advice what to do?

Best Answer

as stated here, you may want to sysctl vm.overcommit_memory=1 as su, and maybe edit /etc/sysctl.conf to add vm.overcommit_memory=1

Related Question