Re: Extremely slow count (simple query, with index)

Поиск
Список
Период
Сортировка
От Justin Pryzby
Тема Re: Extremely slow count (simple query, with index)
Дата
Msg-id 20190822180400.GI15332@telsasoft.com
обсуждение исходный текст
Ответ на Re: Extremely slow count (simple query, with index)  (Justin Pryzby <pryzby@telsasoft.com>)
Список pgsql-performance
On Thu, Aug 22, 2019 at 07:54:57PM +0200, Marco Colli wrote:
> I have completely solved (from 17s to 1s) by running this command:
> vacuum analyze subscriptions;

Thanks for following though.

On Thu, Aug 22, 2019 at 08:19:10AM -0500, Justin Pryzby wrote:
> You can see it used the same index in both cases, and the index scan was
> reasonably fast (compared to your goal), but the heap component was slow.
> 
> I suggest to run VACUUM FREEZE on the table, to try to encourage index only
> scan.  If that works, you should condider setting aggressive autovacuum

I should've used a better word, since aggressive means something specific.
Perhaps just: "parameter to encourage more frequent autovacuums".

> parameter, at least for the table:
> ALTER TABLE subscriptions SET (AUTOVACUUM_VACUUM_SCALE_FACTOR=0.005);
> -- And possibly lower value of autovacuum_freeze_max_age
> 
> Or, running manual vacuum possibly during quiet hours (possibly setting
> vacuum_freeze_table_age to encourage aggressive vacuum).

I think my reference to autovacuum_freeze_max_age and vacuum_freeze_table_age
were incorrect; what's important is "relallvisible" and not "relfrozenxid".
And xid wraparound isn't at issue here.

> > Even an approximate count would be enough.
> 
> You can SELECT reltuples FROM pg_class WHERE oid='subscriptions'::oid, but its

Should be: oid='subscriptions'::regclass

> accuracy depends on frequency of vacuum (and if a large delete/insert happened
> since the most recent vacuum/analyze).

Justin



В списке pgsql-performance по дате отправления:

Предыдущее
От: Marco Colli
Дата:
Сообщение: Re: Extremely slow count (simple query, with index)
Следующее
От: Gunther
Дата:
Сообщение: Re: Out of Memory errors are frustrating as heck!