The error, verbatim
Jump to the fix ↓D1_ERROR: D1 query result exceeded the maximum response size limit of 50 MB
The fix that worked
Select only the columns you need, and page through big tables by key:
SELECT id, title FROM docs
SELECT id, title, body FROM docs WHERE id > ? ORDER BY id LIMIT 20Not it? Every cause, tested ↓Tested on
- Database
- Cloudflare D1 (free plan), through a remote binding
- Wrangler
- 4.136.2 (remote binding); 4.136.2 and 4.162.0 (local)
- Node
- 24.14.0 on Windows 11
- When
- November 15, 2026
Contents
A Worker query that worked for months now throws D1_ERROR: D1 query result exceeded the maximum response size limit of 50 MB. Cloudflare’s changelog of 30 October announced it: from 4 November 2026, D1 fails any query whose result is larger than 50 MB. Only imports and exports through the REST API are exempt. The query didn’t change; the rule did.
Make each query return less than 50 MB. Two changes cover almost every case:
- Name the columns. A
SELECT *that drags a largebody,htmlorblobcolumn into a list page is the usual culprit.SELECT id, title FROM docson the same table passed. - Page by key when you really need every row and every column:
let last = 0;
for (;;) {
const { results } = await env.DB
.prepare('SELECT id, title, body FROM docs WHERE id > ? ORDER BY id LIMIT 20')
.bind(last)
.all();
if (results.length === 0) break;
// ...use results...
last = results[results.length - 1].id;
}You can’t see it in wrangler dev
The same Worker and the same 60 rows, run with wrangler dev --local, returned all ~60 MB from SELECT * without an error, on wrangler 4.136.2 and on 4.162.0, the newest on 15 November. The local runtime doesn’t enforce the limit, so tests that run against local D1 still pass while production fails.
To reproduce it before you deploy, point the binding at a real database. In wrangler.toml, remote = true makes wrangler dev use the real D1 while the Worker still runs on your machine:
[[d1_databases]]
binding = "DB"
database_name = "my-test-db"
database_id = "<id from wrangler d1 create>"
remote = true
Use a throwaway database for this, not production: the seed step below writes about 60 MB.
Where the cut is
I narrowed it down with substr() so only the size changed, not the row count:
| Result (50 rows, one text column) | Bytes of values | Real D1 |
|---|---|---|
LIMIT 49 of 1,000,000-byte rows |
49,000,000 | worked |
| 50 rows cut to 999,990 bytes | 49,999,500 | worked |
| 50 rows cut to 999,999 bytes | 49,999,950 | failed |
LIMIT 50 of 1,000,000-byte rows |
50,000,000 | failed |
So the limit is 50,000,000 bytes (decimal megabytes, not 50 MiB, which would be 52,428,800). A few bytes per row are counted on top of the values themselves: here, between 1 and 10 bytes per row for one short column. Don’t size pages to the edge.
Three ways it still trips after you “fixed” it
How big should a page be
Divide what you can afford by the size of one row. The calculator does that from a sample row, keeps a margin, and writes the keyset loop for your table:
Page-size calculator
Paste one typical row as JSON (what .first() gives you), or type an average row size. It works out how many rows fit in one query with room to spare, and writes the paging query for your table. Nothing leaves this page.
Enter a row or a size to see the page size.
With the default 80% margin, 1,000,000-byte rows give pages of 39 rows (the 20-row pages in the test sit well inside that), and 4,000-byte rows give pages of 9,975 rows. If a single row is close to D1’s 2 MB row limit, even small pages get slow: fetch the big column only on the page that shows it.
Why keyset rather than OFFSET
Both loops above read every row here. OFFSET still makes SQLite step over all the earlier rows on every page, so later pages of a large table get slower, and a row inserted or deleted during the loop shifts everything after it, so a row can be read twice or skipped. WHERE id > ? ORDER BY id starts where the last page stopped. It needs a unique, ordered key: the integer primary key works; for a text key, order by it the same way in every page.
Reproduce it
The test table:
CREATE TABLE docs (id INTEGER PRIMARY KEY, title TEXT, body TEXT);
The Worker filled it with 60 rows of 'x'.repeat(1000000) in six batch() calls of 10 inserts, then ran each query from a separate route and returned { ok, rows } or the error text. On failure, e.message was D1_ERROR: D1 query result exceeded the maximum response size limit of 50 MB, and e.cause carried the same text without the D1_ERROR: prefix.
Sources: Cloudflare changelog, “D1 will enforce a maximum query result size of 50 MB” (30 October 2026), and the D1 limits page.
— N.K., end of entry No.102