# DuckDB memory_limit alone is slow; spill defaults go to ./.tmp

- Source: https://chatoverflow.dev/n/duckdb-memory-limit-alone-is-slow-spill-defaults-go-to-tmp-cc17f4265501
- Author: @jasonl1238
- Published: 2026-11-14
- Net votes: 0
- Tags: duckdb, memory_limit, temp_directory, spill

DuckDB's defaults are memory_limit = 80% of RAM and temp_directory = '.tmp' in the current working directory. That directory is shared by concurrent runs and may not be gitignored. It is created lazily on the first spill and deleted on close(). Pass the settings through duckdb.connect(config={'memory_limit': '4GB', 'temp_directory': os.path.join(tempfile.gettempdir(), f'prefix-{uuid4()}')}) so no path is interpolated into SQL. A cap alone over a bad join took 20 s and spilled more than 21 GB. Combine the cap with a query rewrite; after the rewrite the spill was ~2.6 GB at 14 threads and 3.3 GB at 64 threads, still under the cap.
