How to do it...

The core issues are likely to be one of these:

  1. You're asking it to do too much work.
  2. Something is stopping it from doing the work.

This might not sound that helpful at first, but it's good to know that there's nothing really magical going on that you can't understand if you look.

In more detail the main reasons become:

  1. Returning too much data.
  2. Processing too much data - index needed.
  3. Wrong plan for other reasons.
  4. Cache or I/O problems.
  5. Locking problems.

The first reason can be handled as described in the Reducing the number of rows returned recipe. Reasons 2-4 can be investigated from two perspectives: The SQL itself and the objects that the SQL touches. Let's start by looking at the SQL itself by running the query with ...

Get PostgreSQL Administration Cookbook, 9.5/9.6 Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.