From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Ayub M <hiayub@gmail.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: postgres vacuum memory limits
Date: Sun, 01 Aug 2021 11:30:00 -0400
Message-ID: <1441441.1627831800@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYeDYxvrm4JrdpH=EUQw=+u10gvN0h7Z0MBFAUHK_qxqA@mail.gmail.com>
References: <CAOS0qEtNxAaG9gR+WATt8p2JgyjmfucgQD-ccoXPYgd0syD50w@mail.gmail.com>
<CAKFQuwYeDYxvrm4JrdpH=EUQw=+u10gvN0h7Z0MBFAUHK_qxqA@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Saturday, July 31, 2021, Ayub M <hiayub@gmail.com> wrote:
>> But when default_statistics_target is increased to 3000, the session usage
>> is 463mb
> IIUC, the analyze process doesn’t consult maintenance_work_mem. It simply
> creates an array, in memory, to hold the random sample of rows needed for
> computing the requested statistics.
Yeah. A sample of N rows of the table is going to take X amount of
memory; playing with [maintenance_]work_mem isn't going to affect that.
If you're not happy with the memory consumption, the statistics target
is exactly the knob that's provided to adjust that.
In an ideal world maybe ANALYZE could work within a memory budget that's
smaller than the sample size, but I think that'd inevitably involve a
lot more I/O and significantly worse performance than what we do now.
In any case it'd require a massive rewrite that breaks a lot of
extensions, since the per-datatype APIs for ANALYZE presume in-memory
data.
Keep in mind also that large statistics targets translate to bloat
everywhere else too, since that implies larger pg_statistic entries
for the planner to consult. So I'm not sure that focusing on ANALYZE's
usage in isolation is a helpful way to think about this. If you can't
afford the amount of memory needed to run ANALYZE, you won't like the
downstream behavior either.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, hiayub@gmail.com
Subject: Re: postgres vacuum memory limits
In-Reply-To: <1441441.1627831800@sss.pgh.pa.us>
References: <CAOS0qEtNxAaG9gR+WATt8p2JgyjmfucgQD-ccoXPYgd0syD50w@mail.gmail.com> <CAKFQuwYeDYxvrm4JrdpH=EUQw=+u10gvN0h7Z0MBFAUHK_qxqA@mail.gmail.com> <1441441.1627831800@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox