I’m facing a strange issue with PostgreSQL query performance. The same query runs in under 1 second during certain periods, but takes around 20 seconds at other times. However, the data volume and other parameters remain the same across both time periods.
If a vacuum has been performed on the table, I would expect consistent performance throughout the day. But in this case, the query runs in 1 second during one half of the day and 20 seconds during the other half.
How can this be handled? What could be the root cause of this behavior?