apache/shardingsphere · error · OverallConnectionNotEnoughException
0
0
Error message
Can not get %d connections one time, partition succeed connection(%d) have released. Please consider increasing the 'maxPoolSize' of the data sources or decreasing the 'max-connections-size-per-query' in properties.
What it means
OverallConnectionNotEnoughException (converted to SQLException) thrown by DriverDatabaseConnectionManager.createConnections when it cannot obtain the requested number of connections from a datasource. Any SQLException from dataSource.getConnection() aborts the loop: all connections already acquired in this batch are closed (partition success released) and the aggregate error is thrown. The message tells you the two knobs: raise the pool's maxPoolSize or lower ShardingSphere's max-connections-size-per-query.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java:401
}
synchronized (dataSource) {
return createConnections(databaseName, dataSourceName, dataSource, connectionSize, connectionContext.getTransactionContext());
}
}
private List<Connection> createConnections(final String databaseName, final String dataSourceName, final DataSource dataSource, final int connectionSize,
final TransactionConnectionContext transactionConnectionContext) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
for (int i = 0; i < connectionSize; i++) {
try {
Connection connection = createConnection(databaseName, dataSourceName, dataSource, transactionConnectionContext);
methodInvocationRecorder.replay(connection);
result.add(connection);
} catch (final SQLException ex) {
for (Connection each : result) {
each.close();
}
throw new OverallConnectionNotEnoughException(connectionSize, result.size(), ex).toSQLException();
}
}
return result;
}
private Connection createConnection(final String databaseName, final String dataSourceName, final DataSource dataSource,
final TransactionConnectionContext transactionConnectionContext) throws SQLException {
Optional<Connection> connectionInTransaction = getConnectionTransaction().getConnection(databaseName, dataSourceName, transactionConnectionContext);
return connectionInTransaction.isPresent() ? connectionInTransaction.get() : dataSource.getConnection();
}
@Override
public void close() throws SQLException {
clearCachedConnections();
}
}
View on GitHub (pinned to e952770a21)
Solutions
- Increase the underlying datasource pool size (e.g. HikariCP maximumPoolSize) so connectionSize per query can be satisfied.
- Lower max-connections-size-per-query in ShardingSphere props so a query reuses fewer connections per shard (memory restriction mode).
- Reduce concurrent heavy queries or shard count involved per statement.
- Check DB-side max_connections and network health if the underlying getConnection error indicates refusal rather than pool exhaustion.
Example fix
# before props: max-connections-size-per-query: 8 # too high for pool size 10 with 4 shards datasource: ds_0: maxPoolSize: 10 # after props: max-connections-size-per-query: 2 datasource: ds_0: maximumPoolSize: 32
Defensive patterns
Strategy: validation
Validate before calling
int poolMax = hikariConfig.getMaximumPoolSize();
int perQuery = configuredMaxConnectionsPerQuery;
if (shardCount * perQuery > poolMax) warn("pool too small"); Try / catch
catch (SQLException ex) { if (ex.getMessage().contains("maxPoolSize")) adjustPoolOrThrottle(); rethrow; } Prevention
- Size maxPoolSize >= shard count x max-connections-size-per-query (for strict mode)
- Lower max-connections-size-per-query for wide OLAP queries
- Monitor pool utilization before peak load
- Watch DB max_connections limits
When it happens
Trigger: A single query routed to many tables/shards needs connectionSize connections from one datasource, and the pool is exhausted or the DB refuses new connections mid-batch (maxPoolSize reached, DB max_connections hit, network failure).
Common situations: High sharding counts with default pool sizes (each query may need several connections per shard); OLAP/large result queries over many shards; concurrent queries exceeding HikariCP maximumPoolSize; DB-side connection limits; long transactions holding pool connections.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/b4a582e1aaf2871a.
Report an issue: GitHub.