At Tradepoint, we had a financial data pipeline running 40+ queries per request. Response times averaged 800ms. After three weeks of systematic EXPLAIN ANALYZE work, we were at 320ms. This post walks through exactly what I did, what I misread, and what actually moved the needle.
The problem with "it's slow"
When a query is slow, the instinct is to add an index. Sometimes that's right. More often, you're indexing the wrong column, or the planner is ignoring your index entirely, or the real problem is N+1 queries and no index will help. Before touching anything, you need to see what PostgreSQL is actually doing.
Run slow queries against a copy of production data, not a dev database with 50 rows. The planner makes completely different decisions based on row counts. A query that uses an index in dev may do a full seq scan in production.
Reading EXPLAIN ANALYZE output
The output looks intimidating. The actual numbers are at the bottom, not the top.
Scroll to the end of the plan and look for Execution Time and Planning Time
separately.
-- Always use ANALYZE to get real execution stats
-- Never run EXPLAIN ANALYZE on a write query in production
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT t.id, t.amount, t.status, u.email
FROM transactions t
JOIN users u ON u.id = t.user_id
WHERE t.status = 'pending'
AND t.created_at > NOW() - INTERVAL '7 days'
ORDER BY t.created_at DESC;Here is what the output looked like on our transactions table:

The key node to find: Seq Scan means PostgreSQL is reading every row.
On a 2M-row table that's almost always wrong. Index Scan is what you want.
The gap between estimated rows and actual rows is your main diagnostic signal —
if the planner estimates 100 rows but gets 40,000, your table statistics are stale.
The index I added — and the one I removed
After reading the plan I added a composite index on (status, created_at).
That dropped the query from 820ms to 190ms. But I also found three indexes
that were never being used — each one slowing every INSERT and UPDATE.
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("payments", "0012_previous")]
operations = [
# Add the composite index the planner needs
migrations.AddIndex(
model_name="transaction",
index=models.Index(
fields=["status", "created_at"],
name="tx_status_created_idx",
),
),
# Remove the index that was never used
migrations.RemoveIndex(
model_name="transaction",
name="tx_amount_idx",
),
]
Every index you add costs write performance. Check pg_stat_user_indexes
regularly. If idx_scan is 0 for an index that has been live for weeks, it is
probably safe to drop.
The result
Starting from 800ms: composite index → 190ms. Removed three unused indexes → 160ms. Rewrote one N+1 query EXPLAIN exposed → 95ms. Not magic — just reading what the database was already telling us.
