# OOM: Memory limit reached

> The dataset reached the maxmemory limit and the eviction policy cannot free enough memory, so Redis refuses write commands.

Source: https://sqlly.app/errors/redis/oom-command-not-allowed
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error prefix: `OOM`
- Category: Memory and persistence

Error message:

```text
OOM command not allowed when used memory > 'maxmemory'.
```

## What it means

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.

## Common causes

- 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.

## 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. |

## How to fix it

1. See where you stand before changing anything:

   ```sql
   INFO memory
   # used_memory_human, maxmemory_human, maxmemory_policy
   CONFIG GET maxmemory
   ```
2. For a cache, let Redis free space itself by switching the policy:

   ```sql
   CONFIG SET maxmemory-policy allkeys-lru
   ```
3. For data that must not be evicted, raise the limit or shrink the dataset, then persist the change:

   ```sql
   CONFIG SET maxmemory 2gb
   CONFIG REWRITE
   ```

## Reproduce it safely

```sql
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'.
```

## How SQLly helps

SQLly prints the OOM line verbatim and INFO memory runs in the same editor, so the ceiling and the policy in force are one query away before you decide between a policy change and a resize.

## Questions

### 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.

## Related errors

- [`Out of Memory Error`](https://sqlly.app/errors/duckdb/out-of-memory): DuckDB: The query hit DuckDB's memory limit
- [`SQLITE_NOMEM`](https://sqlly.app/errors/sqlite/sqlite-nomem): SQLite: out of memory
- [`53200`](https://sqlly.app/errors/postgresql/53200): PostgreSQL: out of memory
- [`701`](https://sqlly.app/errors/sql-server/701): SQL Server: Insufficient memory in resource pool

The code and message text are from the [Redis documentation and source code](https://redis.io/docs/latest/).
