Redis is configured to save RDB snapshots, but is currently not able to persist on disk
Asked Answered
V

7

54

I get the following error, whenever I execute any commands that modify data in redis

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.

I installed redis using brew on mac. How can I get the location of log files where redis-server logs information to. I tried looking for redis conf. file, but couldn't find it either.

What is the default location of [1] redis conf file [2] redis log file.

How do I get rid of the above error, and be able to execute commands that modify data in redis.

Vivien answered 9/11, 2013 at 6:18 Comment(2)
see #19581559 for a way to solve this without restarting or losing data.Scenarist
Restarting redis resolved this issue for me, based on #19581559Jagged
V
29

When installing with brew the logfile is set to stdout. You need to edit /usr/local/etc/redis.conf and change logfile to something else. I set mine to:

logfile /var/log/redis-server.log

You'll also make sure the user that runs redis has write permissions to the logfile, or redis will simply fail to launch completely. Then just restart redis:

brew services restart redis

After restarting it'll take a while for the error to show up in the logs, because it happens after redis fails its timed flushes. You should be seeing something like:

[7051] 29 Dec 02:37:47.164 # Background saving error
[7051] 29 Dec 02:37:53.009 * 10 changes in 300 seconds. Saving...
[7051] 29 Dec 02:37:53.010 * Background saving started by pid 7274
[7274] 29 Dec 02:37:53.010 # Failed opening .rdb for saving: Permission denied

After a brew install it attempts to save to /usr/local/var/db/redis/ and since redis is probably running as your current user and not root, it can't write to it. Once redis has permission to write to the directory, your logfile will say:

[7051] 29 Dec 03:08:59.098 * 1 changes in 900 seconds. Saving...
[7051] 29 Dec 03:08:59.098 * Background saving started by pid 8833
[8833] 29 Dec 03:08:59.099 * DB saved on disk
[7051] 29 Dec 03:08:59.200 * Background saving terminated with success

and the stop-writes-on-bgsave-error error will no longer get raised.

Vitalis answered 28/12, 2013 at 18:36 Comment(1)
Since this was written, the redis configuration file location has moved to /opt/homebrew/etc/redis.confQuinquagesima
A
10

So I guess it is a bit late for adding an answer here but since I wondered on your question as I had the same error. I got it solved by changing my redis.conf 's dir variable like this:

# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# 
# The Append Only File will also be created inside this directory.
# 
# Note that you must specify a directory here, not a file name.
dir /root/path/to/dir/with/write/access/

The default value is: ./, so depending on how you launch your redis server you might not be able to save snapshots.

Hope it helps someone !

Astred answered 16/9, 2014 at 15:58 Comment(0)
M
4

In my case i resolved this issue with below steps

Cause : By default redis store data @ ./ and if redis runs with redis user this means redis will not be able to write data in ./ file then you will face above error.

Resolution : Step # 1 (Enter a valid location where redis can do write operations) root@fpe:/var/lib/redis# vim /etc/redis/redis.conf

dir /var/lib/redis # ( This location must have right for redis user to write)

Step # 2 (Connect to redis cli and map directory to write and issue below variable)

127.0.0.1:6379> CONFIG SET dir "/var/lib/redis"

127.0.0.1:6379> BGSAVE -

This will enable redis to write data on dump file.

Mateusz answered 18/10, 2017 at 12:2 Comment(0)
T
3

Steps to fix this error:

Go to redis cli by typing redis-cli

127.0.0.1:6379> config set stop-writes-on-bgsave-error no

after that try to set key value

127.0.0.1:6379> set test_key 'Test Value'
127.0.0.1:6379> get test_key
"Test Value"
Tardiff answered 10/8, 2021 at 4:40 Comment(0)
G
2

Was going through the github discussion and the proposed solution is to run

config set stop-writes-on-bgsave-error no in the redis-cli. here's the link https://github.com/redis/redis/issues/584#issuecomment-11416418

Granddaddy answered 15/2, 2021 at 20:7 Comment(0)
A
1

Check the following places:

/usr/local/Cellar/redis...
/usr/local/var/log/redis.log
/usr/local/etc/redis.conf

This error often indicates an issue with write permissions, make sure you're RDB directory is writable.

Armil answered 9/11, 2013 at 9:39 Comment(0)
T
1

It is usually because permission limits. In my case, it's redis disabled write options.

You can try to run redis-cli in the shell, and then run the following command:

set stop-writes-on-bgsave-error yes
Tideway answered 19/12, 2013 at 3:28 Comment(4)
This answer should not have 5 upvotes because it is misleading. The "stop-writes-on-bgsave-error" is a redis setting which could be used to ask redis server to stop accepting writes if the bgsave (of dump.rdb) fails. This in turn is to let the user know of such failures. s3-us-west-2.amazonaws.com/scaleyourcode/images/blog/redis/…Torrid
As old as this is, feel obligated to add that the answer is misleading as stated above. I was able to fix the given error in the question by going into the redis.conf file and changing stop-writes-on-bgsave-error yes to no. However I would not do this unless you're strictly using redis for caching and sessions.Dorran
This will raise some restore issues obviously, since writes will go on without snapshotting.Tiaratibbetts
This should set to "no" redis 127.0.0.1:6379> config set stop-writes-on-bgsave-error noEnterotomy

© 2022 - 2024 — McMap. All rights reserved.