Skip to content

Instantly share code, notes, and snippets.

@kapkaev
Created January 24, 2013 09:30
Star You must be signed in to star a gist
Save kapkaev/4619127 to your computer and use it in GitHub Desktop.
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. Resque
$ redis-cli
> config set stop-writes-on-bgsave-error no
@abhisheksarka
Copy link

I checked the Redis logs which lead me to "Can't save in background: fork: Cannot allocate memory". This in turn lead me to this

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 says Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.

@abhisheksarka
Copy link

Make sure to set the Linux kernel overcommit memory setting to 1. Add vm.overcommit_memory = 1 to /etc/sysctl.conf and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect immediately. https://redis.io/topics/admin

@angeldev20
Copy link

Thank you.

Copy link

ghost commented Feb 22, 2019

Thanks ( :

@bhavinjr
Copy link

Working 👍

@gabmontes
Copy link

Thanks!

@iamrexan
Copy link

@summerblue when i increase the disk size is again get full .how i can solve this.

@Nleuchter
Copy link

Thanks bro

@nasrulhazim
Copy link

thanks!

@mikgn
Copy link

mikgn commented Dec 19, 2019

Thanks!

@jpcmf
Copy link

jpcmf commented Apr 16, 2020

Works!

@Nevillealee
Copy link

Still works!

@FernandoBello
Copy link

Great ! 👍

@ingemar
Copy link

ingemar commented Jun 15, 2020

Thank you!

@jPingua
Copy link

jPingua commented Jun 23, 2020

I encountered this issue and my senior was unreachable. I thought I was booked for the day, but this code helped me fix the issue in minutes.

@Barolina
Copy link

++++

@alvinyeyint
Copy link

Thanks man !

@sailing
Copy link

sailing commented May 25, 2021

CONFIG SET dbfilename temp.rdb

This is the way,

What u should be doing is :

# redis-cli
127.0.0.1:6379> CONFIG SET dir /data/tmp
OK
127.0.0.1:6379> CONFIG SET dbfilename temp.rdb
OK
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379>

Please Make sure /data/tmp has enough disk space.

this is the way. Thank you for solving the root problem :)

@rajj6
Copy link

rajj6 commented Jun 11, 2021

Yep, this happing because current use does not have the permission to modify the "dump.rdb".

So, instead of creating a new RDB file, You can also give permission to old file(change the ownership of it).

In redis-cli enter:

config get dir

you will get "/usr/local/var/db/redis" (this is the location where redis writes the data)

go to this location using terminal

cd 
cd /usr/local/var/db

Type this command(with our username):

sudo chown -R [username] db

This will change to owner.

This works for me.

@a-mellor
Copy link

a-mellor commented Jul 7, 2021

Yep, this happing because current use does not have the permission to modify the "dump.rdb".

So, instead of creating a new RDB file, You can also give permission to old file(change the ownership of it).

In redis-cli enter:

config get dir

you will get "/usr/local/var/db/redis" (this is the location where redis writes the data)

go to this location using terminal

cd 
cd /usr/local/var/db

Type this command(with our username):

sudo chown -R [username] db

This will change to owner.

This works for me.

This worked with the addtion of stopping and starting redis

brew services stop redis

brew services start redis

@winhc
Copy link

winhc commented Jul 16, 2021

Thanks, that great 👍

@muhiddingithub
Copy link

It was helped for me 👍

@minhhungit
Copy link

For me, my hard disk is out of space

@AhmedSamyAbdelsalam
Copy link

Thanks it's work

@Cibsmart
Copy link

Cibsmart commented Mar 2, 2022

Thank you!

@Artorios
Copy link

Thanks!

@romain130492
Copy link

that's what the command does


  According to Redis documentation, this is recommended only if you don't have RDB snapshots enabled or if you don't care about data persistence in the snapshots.
  
  "By default Redis will stop accepting writes if RDB snapshots are enabled (at least one save point) and the latest background save failed. This will make the user aware (in a hard way) that data is not persisting on disk properly, otherwise,strong text chances are that no one will notice and some disaster will happen."

https://stackoverflow.com/questions/19581059/misconf-redis-is-configured-to-save-rdb-snapshots

@Artorios
Copy link

in addition, I want to say that such errors can appear if the radis server is accessible from outside. You need to configure the radis server to listen only localhost. To do this, in the /etc/redis/redis.conf file, change bind parameter to 127.0.0.1
nano /etc/redis/redis.conf
bing 127.0.0.1
After this:
netstat -lnp | grep redis
should show that redis listning 127.0.0.1 insteed 0.0.0.0:*

@Felix-Qi-Wang
Copy link

thank you from 2022

@ndimic
Copy link

ndimic commented Dec 6, 2022

Thank you!

@lowkeyalex
Copy link

lowkeyalex commented Jan 21, 2024

CONFIG SET dbfilename temp.rdb

This is the way,

What u should be doing is :

# redis-cli
127.0.0.1:6379> CONFIG SET dir /data/tmp
OK
127.0.0.1:6379> CONFIG SET dbfilename temp.rdb
OK
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379>

Please Make sure /data/tmp has enough disk space.

this is the way. Thank you for solving the root problem :)

i keep getting "ERR Changing directory: No such file or directory" im not that good with ubuntu and ideas why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment