Error 202: TOO_MANY_SIMULTANEOUS_QUERIES
This error occurs when the number of concurrently executing queries exceeds the configured limit for the server or user. It indicates that ClickHouse is protecting itself from overload by rejecting new queries until existing queries complete.
Most common causes
-
Exceeded global query limit
- More queries than
max_concurrent_queriessetting allows - Default limit is typically 1000 concurrent queries
- Query execution slower than query arrival rate
- More queries than
-
Exceeded per-user query limit
- User exceeds
max_concurrent_queries_for_userlimit - Multiple applications using the same user account
- Query backlog from slow-running queries
- User exceeds
-
Query execution bottleneck
- Queries running slower than normal (cold cache, resource contention)
- Increased query complexity or data volume
- Insufficient server resources causing query queueing
-
Traffic spike or load test
- Sudden increase in query rate
- Load testing without appropriate limits
- Retry storms from client applications
-
Async insert backpressure
- Large number of async insert operations queueing
- Inserts counted toward query limit
- Async insert processing slower than arrival rate
-
Poor connection management
- Client opening too many persistent connections
- Connection pooling misconfigured
- Each connection running queries simultaneously
Common solutions
1. Implement client-side retry with backoff
This is the recommended approach rather than just increasing limits:
2. Check current query limits
3. Monitor concurrent query count
4. Increase query limits (if appropriate)
In ClickHouse Cloud, changing max_concurrent_queries requires support assistance.
5. Optimize slow queries
6. Implement connection pooling
7. Use query priorities
Common scenarios
Scenario 1: Traffic spike
Cause: Sudden increase in query rate from 200 to 1000+ queries/second.
Solution:
- Implement exponential backoff retries in client
- Scale horizontally (add more replicas)
- Optimize queries to complete faster
- If sustained load, increase
max_concurrent_queries
Scenario 2: Slow queries creating backlog
Cause: Queries taking 3-4 seconds instead of typical 7ms due to cold cache after restart.
Solution:
- Warm up cache after restarts with key queries
- Optimize slow queries
- Implement query timeout limits
- Use query result cache for repeated queries
Scenario 3: Per-user limit exceeded
Cause: Single user running too many concurrent queries.
Solution:
Scenario 4: Async inserts causing limit
Cause: High volume async inserts filling query slots.
Solution:
Scenario 5: Connection pool misconfiguration
Cause: Each client connection running queries, with 1000 open connections.
Solution:
- Reduce connection pool size
- Reuse connections for multiple queries
- Close idle connections
Prevention tips
- Implement retry logic: Always retry with exponential backoff for error 202
- Monitor query concurrency: Set up alerts for approaching limits
- Optimize query performance: Faster queries = lower concurrency
- Use appropriate connection pools: Don't create excessive connections
- Set query timeouts: Prevent queries from running indefinitely
- Use query priorities: Differentiate critical from non-critical queries
- Scale horizontally: Add replicas to distribute load
Debugging steps
-
Check current concurrent queries:
-
Identify query patterns:
-
Check recent error occurrences:
-
Analyze query rate trends:
-
Find slow queries causing backlog:
-
Check connection distribution (for clusters):
Query limit settings
Best practices for high-concurrency workloads
-
Scale horizontally:
- Add more replicas to distribute load
- Use load balancing across replicas
- Better than just increasing limits on single instance
-
Optimize queries:
- Use appropriate indexes and primary keys
- Avoid full table scans
- Use materialized views for aggregations
- Add
LIMITclauses where appropriate
-
Batch operations:
- Combine multiple small queries into fewer large ones
- Use
INclauses instead of multiple queries - Batch inserts instead of row-by-row
-
Use result caching:
-
Implement rate limiting:
- Limit query rate on client side
- Use queuing systems (e.g., RabbitMQ, Kafka) for request management
- Implement circuit breakers
If you're experiencing this error:
- Check if this is a traffic spike or sustained high load
- Monitor concurrent query count in
system.processes - Implement exponential backoff retries in your client
- Identify and optimize slow queries causing backlog
- Consider horizontal scaling before increasing limits
- If sustained high concurrency needed, request limit increase (Cloud) or update config (self-managed)
- Review connection pooling configuration
Related documentation: