bigywater.tech
常见报错 · 10

Redis MISCONF:BGSAVE 失败后连 PING 都被拒,stop-writes-on-bgsave-error no 只是掩盖问题

MISCONF Redis is configured to save RDB snapshots, but it’s currently unable to persist to disk 是线上最容易被搜索的 Redis 报错之一。网上的答案大多是“CONFIG SET stop-writes-on-bgsave-error no”,但这只是让报错消失。这篇在本机把它复现出来,看清楚触发条件、哪些命令受影响、该看哪份日志、怎么真正恢复。

PING
触发 MISCONF 后连 PING 也被拒绝,靠 PING 探活的脚本会误判
3 个条件
拒写要同时满足:配置了保存点、上一次 BGSAVE 失败、stop-writes-on-bgsave-error 为 yes
err → ok
修好目录并手动 BGSAVE 成功后,rdb_last_bgsave_status 变回 ok,写命令不用重启就恢复

复现与受影响的命令

实测 · 本机执行输出
  起始: save = '3600 1',stop-writes-on-bgsave-error = yes
  顺带:运行时想用 CONFIG SET dir 改目录 -> (error) ERR CONFIG SET failed (possibly related to argument 'dir') - can't set protected config
  > BGSAVE
      "Background saving started"
  rdb_last_bgsave_status = err
  > SET k after
      (error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
  > INCR counter
      (error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
  > DEL k
      (error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
  > GET k
      "before"
  > PING
      (error) MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
  > DBSIZE
      (integer) 1

写命令全部返回 MISCONF,读命令正常,PING 也被拒绝。顺带:运行时 CONFIG SET dir 默认被保护配置拒绝。

看哪份日志

实测 · 本机执行输出
  * Background saving started by pid 96718
  # Failed opening the temp RDB file temp-96718.rdb (in server root dir <rdata>/o10_ro) for saving: Permission denied
  # Background saving error

客户端报错只说持久化失败;Redis 日志里有 Failed opening the temp RDB file … Permission denied 这样的具体原因。

触发条件

实测 · 本机执行输出
  配置了保存点(save 3600 1),stop-writes yes(默认):rdb_last_bgsave_status = err,SET -> (error) MISCONF Redis is configured to save RDB snapshots, b
  没有保存点(save ""),stop-writes yes(默认):rdb_last_bgsave_status = err,SET -> "OK"
  配置了保存点,CONFIG SET stop-writes-on-bgsave-error no:rdb_last_bgsave_status = err,SET -> "OK"

需要同时有保存点、上次 BGSAVE 失败、stop-writes-on-bgsave-error 为 yes。去掉任何一个都不会拒写,但去掉前两个意味着数据没有被持久化。

怎么恢复

实测 · 本机执行输出
  故障中: rdb_last_bgsave_status = err,SET -> (error) MISCONF Redis is configured to save RDB ...
  CONFIG SET stop-writes-on-bgsave-error no 之后: SET -> "OK",rdb_last_bgsave_status 仍是 err
  改回 yes: SET -> (error) MISCONF Redis is configured to save RDB ...
  chmod 755 把目录改回可写(此时还没有重新 BGSAVE): SET -> (error) MISCONF Redis is configured to save RDB ...
  > BGSAVE
      "Background saving started"
  BGSAVE 成功之后: rdb_last_bgsave_status = ok,SET -> "OK"

临时放开 stop-writes-on-bgsave-error 只是掩盖问题;修好目录权限或磁盘后手动 BGSAVE 一次,状态变 ok,写命令就恢复。

分步演示

持久化失败
本步的对象

    本文用到的工具与边界

    • 本机 macOS 27 arm64 / MySQL 26.10.0 与 Redis 8.10.2(Homebrew,每个实验自己起实例,端口 9150 以上,只监听 127.0.0.1,不碰本机已有的实例)/ Python 3.15.0 + PyMySQL(按各篇注明用到哪些及版本);报错文本都是真实复现时原样捕获的;计时用 time.perf_counter,数字每次运行会有小幅抖动。本篇用一个自己起的 Redis 8.10.2 实例(端口 8110 起,启动时 dir 指向权限 555 的目录),用纯标准库的 RESP 客户端发命令;失败的 BGSAVE 来自子进程无法创建临时 RDB 文件(Permission denied)
    • 没有验证:磁盘写满(No space left on device)时的表现;AOF 写入失败时的另一个 MISCONF 文本;Redis 复制和 Sentinel / Cluster 在此状态下的行为(主库拒写时 Sentinel 是否会判定下线);云厂商托管 Redis 的参数名与默认值;Redis 7.0 之前的版本
    京ICP备2026067502号-1京公网安备11010502063487号