fix(export): stream database dump in batches for large DBs #59#266
Open
FishEnjoyer2025 wants to merge 1 commit into
Open
fix(export): stream database dump in batches for large DBs #59#266FishEnjoyer2025 wants to merge 1 commit into
FishEnjoyer2025 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #59 — database dumps failing on large databases.
Problem
dumpDatabaseRouteassembled the entire dump in a single in-memory string and read eachtable with one unbounded
SELECT *. On large databases this exhausts memory and/orexceeds the 30s request window.
Fix
ReadableStream, so bytes flow to the client as they'reproduced — the connection stays active instead of buffering one giant body, which keeps
the request from hitting the 30s wall.
LIMIT/OFFSET, default 1000 rows), so memoryusage stays roughly constant regardless of table size.
500 (rather than a half-streamed 200).
batchSizeis an optional parameter for tuning.Tests
All existing
dump.test.tscases still pass, plus a new one verifying that a table largerthan the batch size is streamed across multiple
OFFSETqueries. 6/6 passing.Notes
This solves the common case (constant memory + no 30s timeout) with no intermediate
storage. For truly massive (10GB+) dumps that could exceed a Durable Object's execution
budget even while streaming, a follow-up could spool to R2 and return a download URL —
happy to do that as a separate PR if you'd prefer that direction.
/claim #59