by pants2 · 2y ago · 0 comments
It's been a while since I've used it at scale, but at my previous job half of our incidents were caused by Postgres randomly deciding to change the query plan for a call that was working just fine. Then I'd go in there and re-write the SQL a few times until it figured out what to do, rinse and repeat every few months.
Prior to that, we tried various indexing strategies, de-normalizing some of the data, but ultimately i found that weird plan inconsistency to be solved by the vacuum job
Most of the time, query flips are due to inaccurate statistics over time. Try changing the default statistics target for the affected column.
Postgres doesnt just randomly do things and will always produce the same result given the same circumstances.
Either you werent running routine maintenance and your statistics are messed up, or the statistics arent properly configured or your data is just poorly stored.