Docs Find and fix real problems

Find slow database queries and N+1 problems

Use the Database page to find the queries that cost your app the most time, spot the same query repeated inside one request (N+1), and fix it.

A page gets slower as the data grows: the more items in a cart or rows in a list, the longer it takes. The usual cause is an N+1: the code asks the database once per item instead of once for the whole list. Other times it's one query that got slow. This page shows how to find both.

The example is Relia's demo shop: the cart page runs the same product query once per item, up to 14 times per request.

What you'll see

  • Home shows it under For you or Worth watching, for example GET /api/cart repeats the same database query (N+1). Database turns Watch.
  • Slow queries show up as Slow database queries in api (postgresql) when a query's p95 passes 1 second and is at least 3 times its usual.

Relia flags an N+1 when the same query runs many times inside one request, in at least 2 requests, and the repeats cost at least 200 ms per request. On its own this is Watch: slow, not broken. It becomes Needs you when it comes with failures or users struggling.

Relia records database calls made inside a request or a background job, from the Node.js, Python and PHP SDKs. Query values are removed before anything leaves your server, so you see WHERE id = ?, never the real ids, emails or text.

Find the cause

  1. Open Database in the menu. It lists every query your services run, grouped by shape, with the values removed. The top shows calls, failures and the slowest query.
  2. Read Repeated queries (N+1). Each row names the API, how many times the query repeats in one request and how much of the request's time it takes, for example up to 14 times per request, 260 ms, almost 90% of the request.
  3. Click Example requests to open real requests. In the trace you see the same query bar repeated one after another.
  4. Read Queries, most total time first. A query can be fast alone and still cost the most because it runs so often. Click a query to see its p50, p95 and p99, its trend, and failed or slow example requests.
  5. Read Tables and collections, most time first to see which table your app spends the most time on, with reads, writes and failures.

Tip: watch Database monitoring for Postgres, MongoDB and Supabase (2 min).

Fix it

  • N+1: load the rows in one query instead of one per item, for example WHERE id IN (...) or a join. With an ORM, use its eager-loading option (include, select_related, with, prefetch_related and so on). 14 trips become one.
  • One slow query: add an index on the columns it filters, joins or sorts on. On Postgres, run EXPLAIN ANALYZE on the query to see where the time goes.
  • A query that runs too often: cache the result, or fetch it once per request instead of in every function that needs it.

On Growth and Pro, Show how to fix on the incident writes the steps from the evidence, and Copy for your AI assistant copies a brief for Claude Code, Cursor or another assistant.

Using Supabase or Postgres?

On the Database page you can also Connect your database with a read-only statistics login. The page then shows connections, the database size, the most expensive queries as Postgres measures them, and scheduled jobs (pg_cron). Relia also tells you when a scheduled job fails or stops running, or when the database is running out of connections. See Database monitoring.

Check the fix worked

Deploy your change. Relia picks up the new version of the service by itself, or click I fixed it on the incident. Relia then watches real traffic. Once the problem stays away for at least 15 minutes with at least 20 requests, the incident says Fix confirmed and you get Your fix worked. On the Database page, the repeated query drops out of Repeated queries (N+1).

Next

Last checked against the product: 1 Nov 2026