by joeyrobert · 7y ago · 0 comments
Only adding indexes with good use of EXPLAIN/EXPLAIN ANALYZE on expected usage patterns yielded good results. Often we'd just blow the indexes away and fiddle until we added the correct one to enable an index scan / index only scan.
Other big boons for us have been using ENUM types where necessary (small known dataset for a column) -- now your column takes 4 bytes instead of N bytes for a string. I find them a bit easier to work in than foreign keys for this optimization because of their direct string mapping.
We've had really good mileage with Datadog's APM tools, RDS performance insights and pghero as you mentioned.
I'm my own worst enemy for indexes, because I'm not only the database administrator but also the analyst. So when I'm trying to solve an ad-hoc problem and encounter a long-running query there's a 99% probability that I may have "accidentally" generated a new index to accelerate that query and then forgotten to remove it when I was done.
Lesson learned, and also a good argument for disaggregating the administrative and analytical user permissions.
Can you give an example?
It sounds like normalising the schema would have similar (perhaps more) benefits.