Slow queries affect application latency, reporting jobs, and database cost. In PostgreSQL interviews, this question tests whether you can diagnose performance issues methodically instead of guessing.
Explain how you would optimize a slow-running query in PostgreSQL. Your answer should cover:
EXPLAIN or EXPLAIN ANALYZEThe interviewer expects a practical, structured explanation rather than a list of random tips. Focus on a repeatable workflow: inspect the execution plan, identify the expensive step, choose an appropriate optimization, and verify the impact. Mention PostgreSQL-specific considerations such as sequential scans, index scans, join strategies, and the trade-offs of adding indexes.