skip to content

Which Redis settings refuse `CONFIG SET`, what reply do you get, and how do you change one on a production primary with a replica?

level: middleimportance: should knowfreq 40%

answer

  1. startup-only versus runtime-changeable
  2. the error names the argument
  3. all pairs or none
  4. restart the replica first

basics

~20 s

Immutable settings such as io-threads and databases reply can't set immutable config; dir and dbfilename reply can't set protected config. Edit the file, restart the replica, move the primary role to it, then restart the old primary.

solid answer

~40 s

In Redis 8.10 most settings accept `CONFIG SET`, but startup-only ones such as `databases`, `io-threads`, `cluster-enabled`, `logfile` and `appendfilename` are immutable and reply `CONFIG SET failed ... can't set immutable config`. `dir` and `dbfilename` are protected and refused unless `enable-protected-configs` allows it. A multi-parameter call is all or nothing, so one refused name leaves the others unchanged. `CONFIG GET *` does not help you tell them apart, because it lists immutable settings too. To change one on a primary with a replica, edit the file on the replica and restart it, confirm it has resynced and shows the new value, move the primary role to it, then do the same to the old primary. `CONFIG REWRITE` cannot do this for you, because the value was never set live.

code

plaintext · 5 lines
plaintext
127.0.0.1:6379> CONFIG SET maxmemory 2gb io-threads 4
(error) ERR CONFIG SET failed (possibly related to argument 'io-threads') - can't set immutable config
127.0.0.1:6379> CONFIG GET io-threads
1) "io-threads"
2) "1"

go deeper

for a junior

Recall that not every setting can change live, name two or three that cannot, such as databases or io-threads, and say that those need a file edit and a restart.

for a middle

Predict the reply: the immutable and protected error texts, the all-or-nothing behaviour of several pairs, and why listing in CONFIG GET proves nothing about whether a setting is changeable.

for a senior

Plan the restart through a replica, and name the trap that a primary restarting empty wipes its replicas. Persist live changes on both nodes before any restart.

for a principal

Treat startup-only settings as capacity decisions made in advance. Choose values such as databases and io-threads at provisioning, because each later change costs a role move on every shard.

## Why some settings refuse A Redis **setting** is read from `redis.conf` at startup. Many can then be changed on the running server with `CONFIG SET`, but some shape things that exist only from startup, such as the number of databases or the threads started for I/O. The 8.10 source marks each setting in a table in `config.c`, and the flags decide the reply. ## The four classes | Class | Examples | `CONFIG SET` reply | How to change it | |---|---|---|---| | Modifiable | `maxmemory`, `appendonly`, `port`, `bind`, `loglevel` | `OK` | `CONFIG SET`, then persist | | Immutable | `databases`, `io-threads`, `cluster-enabled`, `daemonize`, `logfile`, `pidfile`, `aclfile`, `appendfilename` | `can't set immutable config` | File and restart | | Protected | `dir`, `dbfilename` | `can't set protected config` | Allow through `enable-protected-configs`, or file and restart | | Not a parameter | `include`, `rename-command`, `loadmodule` | `Unknown option or number of arguments for CONFIG SET` | File and restart | The full immutable error reads `ERR CONFIG SET failed (possibly related to argument 'io-threads') - can't set immutable config`. A few details keep this table honest: - `enable-protected-configs` is itself immutable and defaults to `no`, so allowing protected settings already needs a restart. - `replicaof` is immutable as a parameter, but the `REPLICAOF` command changes the role at runtime. - Modules can be loaded at runtime with `MODULE LOAD`, where `enable-module-command` allows it. ## All or nothing Since Redis 7.0 `CONFIG SET` takes several pairs. It checks every name first, and one immutable, protected, unknown or repeated name fails the call before anything is set. If a value is rejected or fails to apply later, the earlier values are restored. So `CONFIG SET maxmemory 2gb io-threads 4` changes neither setting. A script that batches settings therefore gets a clean failure, but it has to read the error to learn which name caused it. ## Finding out which class a setting is in The `CONFIG SET` page says to run `CONFIG GET *` to list the parameters `CONFIG SET` supports. The 8.10 code does not bear that out: `CONFIG GET` filters only hidden settings out of pattern matches and returns immutable ones like any other. So being listed proves only that the setting exists. Try it on a test node, read the flag in `config.c`, or look for a startup-only note in the `redis.conf` comments. ## Changing one on a live primary Take the reserved case: turning on `io-threads 4` for a primary with one replica, with no outage. The Redis administration page treats this as the same job as a version upgrade: a restart is required, so you follow the replica procedure. 1. On both nodes, run `CONFIG REWRITE` or update the file first if live changes exist, or the restart loses them. 2. Edit the file on the replica and restart it. 3. Confirm `CONFIG GET io-threads` shows the new value and `master_link_status:up` appears in `INFO replication`. 4. Move the primary role to the replica, using Sentinel, `FAILOVER` or a paused cutover. 5. Edit the file on the old primary, restart it, and let it rejoin as a replica. 6. Move the role back only if something depends on which node is primary. ## What can go wrong - **Restarting a primary in place with persistence off.** The administration page warns that a primary restarting with an empty data set wipes its replicas, because they copy it exactly. Move the role first, or make sure persistence is on and that restart is not automatic. - **Editing the file and forgetting it.** A file edit does nothing until the restart, so a node can run for months with a value that differs from its file. Compare `CONFIG GET` with the file before relying on either. - **Moving on too early.** A restarted replica may need a full sync and has to load its data before it is useful. Move the role only after `master_link_status:up`, or the new primary can lack recent writes. - **Changing a setting that must fit the data.** Lowering `databases` below an index holding data makes the RDB load fail and the server exit. - **Assuming `CONFIG REWRITE` queues a change.** It records effective values, and an immutable setting's effective value has not changed.

  • Can you lower the Redis `databases` setting with a restart whenever you like?
    Only if no data lives at an index the new value excludes. Loading an RDB that uses a higher index fails with a fatal message that the data file was created with a server configured to handle more databases than this one. Move or remove that data first, and test on a copy.
  • If `CONFIG GET *` lists a Redis parameter, does that mean `CONFIG SET` can change it?
    No. In 8.10 `CONFIG GET` returns immutable settings such as `databases` and `io-threads` too; only hidden settings are left out of pattern matches. The `CONFIG SET` page reads as if the list were the supported set, so test the setting on a non-production node instead of trusting the listing.

  • Every redis.conf directive can be changed at runtime with CONFIG SET.
  • If CONFIG GET * lists a parameter, CONFIG SET can change it.
  • In a multi-parameter CONFIG SET, valid parameters still apply when another is refused.
  • An immutable setting can be queued with CONFIG REWRITE for the next restart.
  • Restarting a primary with persistence off is safe because its replicas keep the data.

Assumes Redis 8.10; which settings are immutable comes from its config.c table, and multi-parameter CONFIG SET dates from 7.0.