Database Reference
In-Depth Information
Why are my queries slowing down?
Queries that used to run in tens of milliseconds suddenly take several seconds.
A summary query for a report that used to run in a few seconds takes half an hour to complete.
Here are some ways to find out what is slowing them down.
Getting ready
Any questions of type "why is this different today than it was last week?", are much easier to
answer if you have some kind of historic data collecting set up.
Things such as Cacti or Munin for monitoring general server characteristics (CPU and RAM
usage, disk I/O, network traffic, load average) are very useful to see what has changed
recently, and to try to correlate this with observed performance of some database operations.
Also, collecting historic statistics data from pg_stat_* tables, be that daily, hourly, or even
every five minutes if you have enough disk space, is also very useful for detecting possible
causes for sudden changes or gradual degradation in performance.
If you have both these statistics gatherings going on, then even better. If you have none, then
the question is actually "Why is this query slow?".
But don't despair, because there are some things you can do to try to restore performance.
How to do it...
First, analyze your database as follows:
db_01=# analyse;
ANALYZE
Time: 6231.313 ms
db_01=#
This is the first thing to try, as it is usually cheap and is meant to be run quite often anyway.
If this restores the query performance, or at least improves current performance considerably,
then it means that autovacuum is not doing its job well, and the next thing to do is to check
why it is so.
 
Search WWH ::




Custom Search