title: Redis - Failed opening .rdb for saving: Permission denied
link: http://jj.isgeek.net/2017/02/redis-failed-opening-rdb-for-saving-permission-denied/
author: Jj
description: 
post_id: 1084
date: 2017/02/25 00:40:10
created_gmt: 2017/02/25 05:40:10
comment_status: open
slug: redis-failed-opening-rdb-for-saving-permission-denied


    Failed opening .rdb for saving: Permission denied
    
This was the error I saw on my redis database when it started to fail. What was mysterious is that the logs showed that the database was working fine for a while and then it stopped working. 
    
    
    [19728] 24 Feb 15:22:04.247 * DB loaded from disk: 12.650 seconds
    [19728] 24 Feb 15:22:04.248 * The server is now ready to accept connections on port 6379
    [19728] 24 Feb 15:26:52.093 * 10 changes in 300 seconds. Saving...
    [19728] 24 Feb 15:26:52.116 * Background saving started by pid 20189
    [20189] 24 Feb 15:27:08.855 * DB saved on disk
    [20189] 24 Feb 15:27:08.874 * RDB: 0 MB of memory used by copy-on-write
    [19728] 24 Feb 15:27:08.967 * Background saving terminated with success
    [19728] 24 Feb 15:32:09.045 * 10 changes in 300 seconds. Saving...
    [19728] 24 Feb 15:32:09.073 * Background saving started by pid 20815
    [20815] 24 Feb 15:32:23.947 * DB saved on disk
    [20815] 24 Feb 15:32:23.964 * RDB: 1 MB of memory used by copy-on-write
    [19728] 24 Feb 15:32:24.076 * Background saving terminated with success
    [19728] 24 Feb 15:34:50.542 # Failed opening .rdb for saving: Permission denied
    [19728] 24 Feb 15:34:50.543 # Failed opening .rdb for saving: Permission denied
    

Why was my .rdb file changing permissions out of the sudden? Looking at several solutions on Stackoverflow pointed to a bad configuration but that would have caused the problem at start up, not for redis to start working and then suddenly change file permissions. 

My problem was that I had 2 `redis-server` instances running with different users! I had started off a daemonized server from shell with `root` user and then I had the normal service running with the `redis` user. 

This caused that when the server running with root had to write to the file it left it with root ownership and the next time that the redis user instance wanted to write it failed. 

The solution was simple, to just kill the root owned process.