Skip to main content

Slow Queries

Every application has slow queries, but not every slow query is a problem. pgpulse helps you identify the queries that are having the biggest impact on your performance.

What "Slow" Means

In pgpulse, we look at latency percentiles:

  • p95: 95% of requests are faster than this.
  • p99: 99% of requests are faster than this (the "long tail").

A query might be fast on average but have a terrible p99 due to lock contention or cold caches.

Common Patterns

  • N+1 Queries: Hundreds of small queries where one join would suffice. Usually caused by ORMs.
  • Missing Indexes: Postgres having to scan the entire table for every filter.
  • Large Result Sets: Pulling thousands of rows just to display five on a page.

Action Checklist

  1. Identify the Top Consumer: Sort by "Total Time" in pgpulse to see what's eating your CPU.
  2. Correlate with Traffic: Is a query slow because it's inefficient, or just because it's called 10,000 times a second?
  3. Analyze the Plan: Look at the suggested improvements in the query detail view.
  4. Optimize: Add an index, rewrite the query, or add caching at the application layer.