Redis cannot save dump.rdb because it is not allowed to write there
Failed opening .rdb for saving: Permission deniedShort answer
Redis writes its snapshot into the directory set by dir, using the account the server runs as. Permission denied means that account cannot write there. Ask the server for its dir, then fix the owner of that folder, or point dir at a folder the redis user owns. Under systemd, also check the unit's sandbox rules.
Fix it fast
1Find out which cause you have
Ask Redis where it writes, and which user the process runs as. The two together show the mismatch.
redis-cli CONFIG GET dir ps -o user= -p "$(pgrep -x redis-server | head -n1)"2Match what you see, then jump to its fix
- 1
The Redis log names the directory it tried to write todir points at a folder the redis user cannot writeFix - 2
dir is ./ or the folder you launched redis-server fromRedis was started by hand and dir defaulted to the current folderFix - 3
Ownership looks right but the write is still refused under systemdThe systemd unit makes the folder read-only for the serviceFix
- 1
What does the error look like?
Failed opening .rdb for saving: Permission deniedPermission denied
Cause 1 of 3
dir points at a folder the redis user cannot write
1Check
The snapshot goes to the folder named by dir, under the name in dbfilename (default dump.rdb). If dir is a folder the server account does not own, the write is refused.
redis-cli CONFIG GET dir
ls -ld "$(redis-cli CONFIG GET dir | tail -n1)"2Fix
Make the folder writable for the account Redis runs as, or set dir in redis.conf to a folder that account owns and restart.
sudo chown -R redis:redis /path/from/CONFIG-GET-dir3Verify
Force a snapshot and read the status.
redis-cli BGSAVE
redis-cli INFO persistence | grep rdb_last_bgsave_statusConfirmed by raw.githubusercontent.com
Cause 2 of 3
Redis was started by hand and dir defaulted to the current folder
1Check
The default of dir is ./, the working directory of the process. Start redis-server from a read-only or foreign folder and every save fails.
redis-cli CONFIG GET dir2Fix
Set an explicit dir in the config file you start Redis with, and start Redis with that file.
# redis.conf
dir /var/lib/redis
dbfilename dump.rdb
redis-server /etc/redis/redis.conf3Verify
The reported dir is the one you set.
redis-cli CONFIG GET dirConfirmed by raw.githubusercontent.com
Cause 3 of 3
The systemd unit makes the folder read-only for the service
1Check
systemd can mount parts of the filesystem read-only for a service. Anything outside the paths the unit lists as writable stays blocked, whatever the file owner is. Read the unit's settings.
systemctl cat redis-server | grep -E 'ProtectSystem|ReadWritePaths|ProtectHome'2Fix
If you moved dir outside the default data folder, add the new path to ReadWritePaths in a drop-in and restart the service.
sudo systemctl edit redis-server
# in the editor add:
# [Service]
# ReadWritePaths=/data/redis
sudo systemctl restart redis-server3Verify
A snapshot now succeeds.
redis-cli BGSAVE
redis-cli INFO persistence | grep rdb_last_bgsave_statusConfirmed by freedesktop.org
How do I stop it coming back?
- Always set dir and dbfilename explicitly in the config file instead of relying on ./.
- When you move dir, change the owner and, under systemd, ReadWritePaths in the same change.
- Alert on rdb_last_bgsave_status not being ok, so a failing save is seen before writes are refused.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Databases
Redis answers every command with LOADING after a restart
(error) LOADING Redis is loading the dataset in memory
LOADING means the server is up but still reading its RDB or AOF file back into memory, so it refuses most commands until that finishes.
3 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fixDatabases
manage.py test stops with 'permission denied to create database' on PostgreSQL
django.db.utils.ProgrammingError: permission denied to create database
Django creates a separate database called test_ plus your database name, using the DATABASES USER.
2 causes, each with a fix