Julien Rouhaud <rjuju123@xxxxxxxxx> writes: > +1, and more generally please follow > https://wiki.postgresql.org/wiki/Slow_Query_Questions. Yeah. FWIW, the most likely explanation for the change in behavior is that by the time of the second execution, auto-analyze has managed to update the table's statistics, and that for some reason that's changing the plan for the worse. But then the next question is why and what can be done about that. See the wiki entry for info that would be helpful in diagnosing this. regards, tom lane