Hacker News new | ask | show | jobs
by smcleod 1150 days ago
Came here to say exactly this. Over the last 12~ years working with PostgreSQL I've dealt with quite a few performance related issues - almost all were poorly written queries.
1 comments

Can you point to some good resources on how to write better postgres queries? Or give examples of common pitfalls?
Start with EXPLAIN ANALYZE then work from there. You can use tools where you paste the output of it and it shows you the data in a more easy to understand format.
I am using https://explain.dalibo.com/ for that exact purpose and it does a great job highlighting the perfs issues.
I don't have any other good recommendations other than learning how to read and use EXPLAIN [1]. This should typically be the first tool when you have a slow query.

[1] https://www.postgresql.org/docs/current/sql-explain.html

An old classic but too many indices can be harmful too.
I would guess the most common pitfall is either not having indices or having the wrong kind of index for your query.