Re: Slow planning time

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Neville <scott(dot)neville(at)bluestar-software(dot)co(dot)uk>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Slow planning time
Date: 2015-12-23 15:24:24
Message-ID: 26165.1450884264@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Scott Neville <scott(dot)neville(at)bluestar-software(dot)co(dot)uk> writes:
> We have a database that for some reason has started to be really slow at planning all queries. The database is running version 9.4.2 since July 28th (it was freshly installed then - compiled from source). The response time is fairly sporadic, but the quickest plan time I have seen (on any query) using explain analyze is 39ms with an execution time of 1ms, however we have slow query logging on and we are getting queries taking over 6000 ms in the planning stage with then only a few ms to execute. There is nothing complex about the queries so even something like this:
> select max(datetime) from audit;
> (where datetime is an indexed field takes 200ms to plan and 0.5ms to execute).

> The databases are involved in a replication chain so I have
> M1 -> S1 -> S2
> I have restarted S2 and S1 and this appears to have made the problem go away (though for how long....). S1 has a replication slot listed on M1.

Please clarify: the slowness occurs on the slaves but not the master?

I am suspicious that the problem has to do with bloat in pg_statistic,
which I will bet that your homegrown vacuuming protocol isn't covering
adequately. I concur with Kevin's nearby advice that you'd be better
off to forget that and use 10 or so autovacuum workers; you can use
autovacuum_cost_limit to throttle their I/O impact, and still be a
lot better off than with just 1 worker.

There is probably something else going on that's replication-specific,
but I'm not sufficiently up on that aspect of things to theorize.

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Artem Tomyuk 2015-12-23 22:27:47 pg_dump
Previous Message Kevin Grittner 2015-12-23 14:28:28 Re: Slow planning time