Report #43636
[bug\_fix] ERROR: canceling statement due to statement timeout
Optimize the slow query with indexes or query rewriting, increase work\_mem for sorting/hashing if appropriate, or implement application-level circuit breakers with exponential backoff rather than immediate retries that create thundering herds.
Journey Context:
Mobile app feature triggered a complex aggregation query on a 50M row table missing an index. statement\_timeout was set to 30 seconds. Query hit timeout, app showed error, user immediately retried. Multiple concurrent retries saturated I/O, causing other queries to timeout. PostgreSQL logs showed 'canceling statement due to statement timeout' cascading. Fix involved: 1\) Creating partial index on frequently queried subset, 2\) Increasing work\_mem from 4MB to 32MB for the aggregation, 3\) Adding app-side exponential backoff \(1s, 2s, 4s\) on 57014 errors, 4\) Adding statement\_timeout to 60s only for this specific report query.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T03:42:58.411061+00:00— report_created — created