CRITICAL

How to Fix Redis MISCONF: Persistence Save Failed

Quick Fix Summary

TL;DR

Run `CONFIG SET stop-writes-on-bgsave-error no` to restore write operations, then investigate and resolve the underlying disk or permission issue.

Redis failed to save its dataset to disk (RDB snapshot) during a background save (BGSAVE). This triggers the MISCONF error and blocks all write operations to prevent data inconsistency.

Diagnosis & Causes

  • Insufficient disk space for the RDB file.
  • Incorrect filesystem permissions on the Redis data directory.
  • Disk is full or experiencing I/O errors.
  • The `save` directive in redis.conf is too aggressive for disk I/O.
  • Running out of inodes on the filesystem.
  • Recovery Steps

    1

    Step 1: Immediate Mitigation - Restore Write Operations

    First, reconnect write capability to your application. This command tells Redis to continue accepting writes even if background saves fail. Use this ONLY as a temporary fix.

    bash
    redis-cli CONFIG SET stop-writes-on-bgsave-error no
    2

    Step 2: Diagnose Disk Space and Inodes

    Check for the most common root cause: lack of storage. Verify both available disk space and inode count.

    bash
    df -h /path/to/redis/data
    df -i /path/to/redis/data
    3

    Step 3: Verify Directory Permissions and Ownership

    Ensure the Redis user (often `redis`) has write permissions to the directory specified by `dir` in the configuration.

    bash
    ls -la /var/lib/redis/
    sudo chown -R redis:redis /var/lib/redis
    sudo chmod 755 /var/lib/redis
    4

    Step 4: Check Redis Logs for Specific Error

    Examine the Redis server logs (location defined in `logfile` or systemd/journalctl) for the exact error message from the failed BGSAVE.

    bash
    sudo tail -100 /var/log/redis/redis-server.log
    sudo journalctl -u redis.service --no-pager -n 50
    5

    Step 5: Manually Trigger a Save to Test

    After addressing potential issues, test if persistence now works by forcing a save. Use SAVE (blocks) or BGSAVE (background).

    bash
    redis-cli SAVE
    # Check for 'OK' response
    6

    Step 6: Re-enable Safe Mode (Post-Recovery)

    Once the root cause is fixed, re-enable the protective setting to prevent future silent data loss on save failures.

    bash
    redis-cli CONFIG SET stop-writes-on-bgsave-error yes
    # Persist the change to redis.conf: `stop-writes-on-bgsave-error yes`
    7

    Step 7: Adjust Persistence Strategy (If Needed)

    If disk I/O is the bottleneck, consider less frequent saves, switching to AOF, or upgrading infrastructure.

    bash
    # Example: Change from save 900 1 300 10 60 10000
    # to save 3600 1 300 100

    Architect's Pro Tip

    "In containerized environments (Docker/K8s), this error often stems from the ephemeral container filesystem filling up. Mount a persistent volume and ensure `vm.overcommit_memory=1` is set on the host."

    Frequently Asked Questions

    Is it safe to set `stop-writes-on-bgsave-error` to `no` permanently?

    No. This disables a critical safety feature. If saves consistently fail, your in-memory data will diverge from disk, leading to complete data loss if Redis restarts. Use it only as a temporary bypass.

    The disk has space, but the error persists. What next?

    Check for I/O errors in `dmesg`, ensure SELinux/AppArmor isn't blocking Redis, and verify the filesystem isn't read-only. Also, test writing a file manually to the `dir` location as the Redis user.

    How does this error differ from a `MISCONF` error about `maxmemory`?

    Both are `MISCONF` but have different causes. `maxmemory` is triggered when the memory limit is reached and no eviction policy is set. This guide specifically addresses the `persistence save failed` variant.

    Related Redis Guides