Estimate maintenance_work_mem for CREATE INDEX

From: Oleksandr Shulgin <oleksandr(dot)shulgin(at)zalando(dot)de>
To: pgsql-admin(at)lists(dot)postgresql(dot)org, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Estimate maintenance_work_mem for CREATE INDEX
Date: 2017-12-19 09:47:12
Message-ID: CACACo5QCnCotZgJaZj8ev92KpBnaS4TCTZzRLkoXZ=q5_n8A7A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-hackers

(cross-posting admin and hackers)

Hello,

I wonder if I'm alone in my wish to have a way for estimating how much
maintenance work memory would suffice to allocate for a session when
creating an index and avoid spilling to disk?

Recently I had to re-create some indexes on a 9.6 server and I had some
input on the on-disk index size: one was around 30 GB, the other -- a bit
over 60 GB according to \di+ output. The total number of live tuples in
the table itself was close to 1.3e+9, the table had an estimated 25% bloat.

I had some spare memory on the machine so I've given it 60 GB for
maintenance_work_mem and expected that at least the smaller of the two will
fit in memory completely. To my surprise that didn't suffice and both
indexes were building with some disk spill.

Is anyone aware of a query to estimate the memory requirements for CREATE
INDEX [CONCURRENTLY]?

I've looked in the postgres wiki, but didn't find anything to that end.
Nor searching the archives of pgsql-admin did help.

I understand that there were some changes in recent releases related to
memory allocation (e.g. allowing huge allocation in 9.4), but at least
targeting 9.6 or 10 would make sense. There are also a lot of ways how one
CREATE INDEX can be different from the other, but in the most simple case
where you have fixed-width columns and building the full index (i.e. no
WHERE clause), it should be possible.

Not hasting to look in the source to calculate all the sizeof()s yet:
waiting on your reply and suggestions. ;-)

Cheers!
--
Oleksandr "Alex" Shulgin | Database Engineer | Zalando SE | Tel: +49 176
127-59-707

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Oleksandr Shulgin 2017-12-19 10:00:01 Re: Estimate maintenance_work_mem for CREATE INDEX
Previous Message Francis Santiago 2017-12-18 17:34:32 Re: Postgresql9.6-plperl9.6 64 bit rhel 7 OS needed

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2017-12-19 09:56:33 Basebackups reported as idle
Previous Message Beena Emerson 2017-12-19 08:54:26 Re: [HACKERS] Runtime Partition Pruning