Connection limit exceeded in DuckDB ConnectionManager: hard limit or advisory threshold?
0 reputation · 13 Feb 2025, 15:28 UTC
0 reputation · 13 Feb 2025, 15:28 UTC
DuckDB’s ConnectionManager enforces a ceiling on concurrent Connection objects. When a new connection is requested while active connections equal the configured max_connections value, the error Connection limit exceeded is raised. The default is commonly 1, though it can be changed with a SET statement.
What remains unclear is whether this limit is advisory or hard across DuckDB releases, and whether the ConnectionManager automatically reclaims idle connections when the threshold is reached. The current design leaves an unresolved decision: expose a connection pool abstraction for user code, or rely on users to close idle connections manually.
Because the default value and enforcement behavior may differ between major versions, and the error wording is version-sensitive, teams should verify behavior against their specific build before relying on it.
max_connections limit intended as a hard cap or an advisory threshold in current DuckDB releases?32275 reputation · 13 Feb 2025, 18:23 UTC
In current DuckDB releases, the max_connections limit is enforced as a hard cap. When the number of active Connection objects reaches this ceiling, any subsequent request for a new connection will immediately raise a Connection limit exceeded error. It does not function as an advisory threshold, nor does it queue requests until a slot becomes available.
DuckDB's ConnectionManager does not provide automatic reclamation of idle connections. A connection remains active until it is explicitly closed by the application or the parent process terminates. Because there is no built-in background reaper for stale connections, leaked handles will exhaust the max_connections quota, necessitating an application restart to clear the state.
Consequently, DuckDB does not provide a native connection pool abstraction for user code. Applications requiring high-frequency connection cycling or concurrent access must implement their own pooling logic or strictly adhere to a manual close() pattern.
with in Python) to guarantee closure regardless of execution success.-- 1. Check current limit
SELECT * FROM duckdb_settings() WHERE name = 'max_connections';
-- 2. Attempt to open (limit + 1) connections to confirm the hard failure.
This behavior assumes the use of DuckDB in its standard embedded mode. Users should be cautious when increasing max_connections for a single database file, as this does not automatically guarantee safe concurrent write performance or eliminate locking contention. If you are using a specific wrapper or a third-party driver, please specify the driver version, as some middleware may implement its own pooling layer independently of the DuckDB core.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.