logoalt Hacker News

traceroute66 • today at 8:24 AM • 5 replies • view on HN

Postgres isn't slow, your schema and queries are.

There. Fixed it for you.

Too many times I see people making the same avoidable mistakes time and time again.

They get stuck in the dream of "portable" schemas and don't use their brain to design a database-specific schema.

They have no clue how to write SQL queries (or again, have stupid dreams of "portable" queries). As a result performance suffers.

Then they come to your desk complaining the databse is slow, and insisting that they absolutely MUST have a Redis caching layer.

I'm sick and tired of people using databases as blackbox dumping grounds. If slow storage was always the problem, my life would be far less stressful. Since the prescription would be easier for the doctor to write. ;)


Replies

s08148692 • today at 9:24 AM

You can spend a week crafting the most optimal query possible, making sure the plans are perfect and all the best index types are used

And then you push it to production and get completely different results

Statistics change everything. Queries which produced beautiful plans in local and staging environments breakdown when given production statistics, some users get the same plans you did, others get nasty nested loops, indexes don't get used, and debugging and fixing it requires poking around in prod statistics which is never a good place to be. Don't even get me started on how RLS impacts query optimisation

Postgres is great but the authors refusal to add plan hints is a decision that comes to bite me at least a few times a year

➕ show 1 reply
smolder • today at 8:45 AM

Yeah, a lot of people can't figure out how to structure databases or what indices to add to them, but no, that is not the only problem just because it's the one you deal with.

➕ show 1 reply
rtp4me • today at 11:21 AM

PGHero an pgtuner are two of our favorite tools to use when optimizing PGSQL

CodesInChaos • today at 8:28 AM

Which postgres specific schema/query features do you use to significantly improve performance?

➕ show 3 replies
boxed • today at 9:15 AM

A good schema and good queries won't save you if your storage is physically far enough away :P

➕ show 1 reply