Diagnostic Queries
Symptoms
A query on a hot standby was cancelled because it conflicted with WAL replay from the primary. PostgreSQL raises SQLSTATE 57014 (query_canceled).
- A read query on a replica was cancelled.
- Recovery (WAL replay) needed to remove rows the query was reading.
- Common on busy hot standbys.
What the server log shows
ERROR: canceling statement due to conflict with recovery
DETAIL: User query might have needed to see row versions that must be removed.
Why PostgreSQL raises this — what the manual says
Section 26.4.2 Handling Query Conflicts:
“Once the delay specified by max_standby_archive_delay or max_standby_streaming_delay has been exceeded, conflicting queries will be canceled.”
On a standby, WAL replay may need to clean up row versions a long-running read query still requires. To keep replay progressing, PostgreSQL cancels the conflicting query with 57014.
Common causes
- Long-running queries on a hot standby.
- Aggressive vacuum/cleanup on the primary.
- Low
max_standby_streaming_delay.
Relevant GUC parameters
| Parameter | Default | Effect |
|---|---|---|
max_standby_streaming_delay |
30s | How long replay waits for conflicting queries before cancelling them. |
hot_standby_feedback |
off | When on, reduces conflicts by informing the primary of standby queries. |
How to fix it
- Enable
hot_standby_feedback = onto reduce cleanup conflicts. - Increase
max_standby_streaming_delayto give queries more time. - Retry the query, or run long analytics against a dedicated replica.
Related & next steps
Reference: PostgreSQL 18 Section 27.4 “Hot Standby”.
Thanks — noted. This helps keep the database accurate.