Always run EXPLAIN with ANALYZE and BUFFERS
Plain EXPLAIN shows you the planner's guess. EXPLAIN (ANALYZE, BUFFERS) shows what actually happened, including how many pages came from cache and how many from disk. Bad plans hide in the gap between estimated and actual row counts.
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;If the actual rows are ten times the estimate, run ANALYZE on the table before you change the query.
postgresqlperformance