Chapter 08 · Clickhouse Managed Postgres Rca
Subchapter 8.5
rules/heuristic-hot-loop.mdMarkdown2 KBView on GitHub
Use when the triage decision tree pointed here: one pattern
has a very high <call_count> and a very low <avg_duration>,
but its <total_duration> is one of the largest on the
instance.
Field names reference roles from your session’s role map
(per openapi-discovery.md). Substitute resolved actual names
when citing values.
A pattern executing thousands of times per minute with a sub-millisecond mean is the application calling the database in a tight loop — typically:
SELECT or INSERT where
a single statement could handle many.The database is healthy here. The caller is the problem.
Strong evidence:
<avg_duration> < ~1 ms but <call_count> is in the tens
of thousands over a short window.<blocks_read_from_disk> per call is small — the query is
cheap; the issue is volume.<query_text> looks like a single-row lookup or small
write: SELECT ... WHERE id = $1, INSERT ... VALUES (...).Weak/contraindicating evidence:
<avg_duration> — that’s not a hot loop, that’s a slow
query at scale.The fix lives in the application, not the database. Be specific about what to look for, since you can’t see the app code:
<query_text>. The framework’s
ORM-generated queries usually have a distinctive shape.SELECT ... WHERE id = ANY($1) with the array of IDs. For writes: INSERT ... VALUES (...), (...), (...) or COPY.<avg_duration> is small; there’s probably already
one. Adding more won’t help.statement_timeout — papers over the loop.