May 2018
Intermediate to advanced
576 pages
30h 25m
English
If you can, then try to run the same slow query when the database has no (or very few) other queries running concurrently. If it runs well in this situation, then it may be that the database host is just overloaded (CPU, memory, or disk I/O) or other applications are interfering with Postgres on the same server. Consequently, a plan that works well under a light load is not so good any more. It may even be that this is not a very good query plan with which to begin, and you were fooled by modern computers being really fast:
db=# select count(*) from t; count --------- 1000000(1 row)Time: 329.743 ms
As you can see, scanning 1 million rows takes just 0.3 seconds on a laptop that is a few ...