I have a linux server running just Postgres with PostGIS Extension. There are several databases on this instance of the Postrges Server.
One of the databases has some computationally intensive queries run on it from time to time. This causes the CPU utilization to jump up to 100% and the sevrer often does not respond to requests.
How to Prevent heavy queries on one database, affecting the performance of other databases on same server? How can I make sure that other databases on that PostGres Instance still respond to requests? Is there a way to prevent one database from consuming all the CPU cycles?
Best Answer
I'll quote a few things from Postgres wiki, Priorities:
Consider this part in in particular:
And especially this:
... test follows ...
So, I'd say that you should:
first, follow the advice above, perform some more analysis tests and make sure that the bottleneck is from the database you suspect and that it's caused by CPU contention (which may well be the case if your queries are so computationally expensive). Or it may be partially true and there's CPU contention but also room for query improvements.
follow the advice in the 2nd paragraph above (improve the queries, generally polish the cluster, check and optimize vacuum and autovaccum settings.)
You should also optimize the various memory settings (mostly
work_mem
) with different values for the clients that connect to this database that has different workload.If after all those, the issue remains, and there are still CPU or disk IO contention or both, there are some options described in the linked Priorities page that you can try ("renice", prioritize extension, etc).
One of the suggestions there (that is certainly worth considering) is separating your databases into 2 clusters (instances), one for the computanionally expensive db and another for all the rest, with the usual workload. See Prioritizing databases by separating into multiple clusters, where it mentions the likely cleaner option:
Separate machines