Prompt
How do I identify the database call slowing down a request
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
To find the database call slowing down a request, you want to measure the request end-to-end, then isolate which query inside it is taking the most time.
Practical approach
1. Measure the request timeline
First determine whether the slowdown is:
- DB time
- application code
- network / serialization
- waiting on locks / connection pool
Use:
- request logs with timestamps
- APM tools like Datadog, New Relic, AppDynamics, Dynatrace
- distributed tracing like OpenTelemetry
If your request is slow, a trace should show where time is spent.
2. Log every database query for that request
Enable query logging temporarily or for slow requests only.
Look for:
- SQL text
- start/end time
- duration
- rows returned
- query parameters
- call stack / source file if possible
Many frameworks can log:
- each SQL statement
- execution time per query
Examples:
- Rails: ActiveRecord query logs
- Django: database query logging
- Node.js: ORM logging or database driver tracing
- Java: datasource proxy, Hibernate statistics, p6spy, datasource-proxy
3. Identify the slow query
Once logged, sort queries by duration:
- longest query in the request
- query repeated many times
- query that returns lots of rows unexpectedly
Watch for:
- N+1 queries
- missing indexes
- large
JOINs SELECT *- full table scans
- lock waits
- slow
ORDER BY,GROUP BY,DISTINCT
4. Correlate with database-side diagnostics
On the DB server, inspect:
- slow query log
- EXPLAIN / EXPLAIN ANALYZE
- query plans
- active sessions / locks
- connection pool saturation
- CPU / I/O pressure
Useful checks:
- Postgres:
pg_stat_statements,EXPLAIN ANALYZE,pg_locks - MySQL: slow query log,
EXPLAIN, performance schema - SQL Server: Query Store, execution plans
- Oracle: AWR/ASH, execution plans
5. Check for non-query DB delays
Sometimes the “DB call” is slow because of:
- waiting for a free connection in the pool
- transaction locks
- deadlocks/retries
- network latency between app and DB
- ORM hydration/deserialization overhead
So separate:
- time waiting to acquire connection
- time executing SQL
- time mapping rows to objects
Fastest way to pinpoint it
If you want a quick answer in production, do this:
- Enable request tracing
- Enable SQL query timing logs
- Reproduce the slow request
- Find the query with the highest duration
- Run
EXPLAIN ANALYZEon it - Check for locks / repeated queries / missing indexes
Example of what you want to see
GET /orders/123 842 ms
auth 12 ms
load user 18 ms
SQL: orders 210 ms
SQL: items 401 ms <-- likely bottleneck
render 89 ms
That makes the slow call obvious.
If you want, I can help you with:
- your specific stack (Rails, Django, Node, Java, .NET, etc.)
- how to log query timings
- how to interpret an EXPLAIN plan
- how to detect N+1 queries or lock waits