OOM: Memory limit reached
The dataset reached the maxmemory limit and the eviction policy cannot free enough memory, so Redis refuses write commands.
- Error prefix
OOM
它的意義
OOM is the write-path refusal when used_memory is over maxmemory and the configured maxmemory-policy cannot free enough: noeviction evicts nothing by definition, and even an allkeys policy can fail when the incoming write is larger than what eviction can reclaim. Read commands keep working, and so do commands without the deny-oom flag, such as DEL; a SET is refused at the limit even when the new value is smaller.
The message names the two knobs precisely: the ceiling is maxmemory and the behavior at the ceiling is maxmemory-policy. Which one to change depends on what the data is: a cache wants an eviction policy; a system of record wants more memory or a smaller dataset.
常見原因
- maxmemory is set and the working set grew past it, with the policy at its default of noeviction.
- An allkeys or volatile policy still could not free enough for the incoming write.
- A single very large value arrives at a moment when eviction has already freed everything it can.
Find the cause
INFO memory # used_memory versus maxmemory, and the policy in force INFO stats | grep evicted # How often eviction already ran to make room redis-cli --bigkeys # Where the bytes are: the largest keys by type
maxmemory policies at the limit
| noeviction | The default. Write commands are refused with OOM, including ones that would not grow memory; reads keep working. |
|---|---|
| allkeys-lru / allkeys-lfu | Evicts the least recently or least frequently used key, across all keys, to fit the write. |
| volatile-* | Evicts only keys with a TTL. When no key has one, it behaves like noeviction. |
| allkeys-random / volatile-random | Evicts a random key from the eligible set. |
如何修正
-
See where you stand before changing anything:
INFO memory # used_memory_human, maxmemory_human, maxmemory_policy CONFIG GET maxmemory
-
For a cache, let Redis free space itself by switching the policy:
CONFIG SET maxmemory-policy allkeys-lru
-
For data that must not be evicted, raise the limit or shrink the dataset, then persist the change:
CONFIG SET maxmemory 2gb CONFIG REWRITE
Other ways to handle it
Split by tier: keep evictable data such as sessions and caches in one instance with allkeys-lru, and durable data in another with noeviction plus alerts on used_memory. On the client, tolerate OOM for best-effort writes but never for ledger-style ones.
安全地重現問題
redis-server --port 7306 --maxmemory 2mb --maxmemory-policy noeviction --save '' & head -c 3000000 /dev/zero | tr '\0' 'a' | redis-cli -p 7306 -x SET big # (error) OOM command not allowed when used memory > 'maxmemory'.
問題
Why do reads still work when writes get OOM?
The limit guards memory growth. Reads are not flagged to be refused at the limit, so Redis serves them, while write commands flagged deny-oom are refused whether or not they grow the dataset.
What does maxmemory 0 mean?
No Redis-side limit: the process grows until the operating system stops it. The OOM refusal only applies when maxmemory is set to a byte value.
相關錯誤
Out of Memory ErrorDuckDB: The query hit DuckDB's memory limitSQLITE_NOMEMSQLite:記憶體不足53200PostgreSQL:記憶體不足701SQL Server:資源集區記憶體不足
More memory and persistence errors
MISCONFPersistence is failing, writes stoppedLOADINGDataset still loading from diskBUSYKEYTarget key already exists
程式碼和訊息文字來自 Redis documentation and source code。瀏覽完整的 Redis error list 或 搜尋每個資料庫錯誤.
Work on Redis in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.
本頁文字與資料: CC BY 4.0,請註明出處 SQLly (sqlly.app)。 程式碼與 SQL 片段: MIT. 授權詳情 引用的錯誤訊息文字歸其資料庫廠商所有。