Configuration parameter work_mem in PostgreSQL on Linux
I posted your query plan on explain.depesz.com, have a look. The query planner’s estimates are terribly wrong in some places. Have you run ANALYZE recently? Read the chapters in the manual on Statistics Used by the Planner and Planner Cost Constants. Pay special attention to the chapters on random_page_cost and default_statistics_target. You might try: ALTER … Read more