Thread: postgres vacuum memory limits
Hello, when maintenance_work_mem and autovacuum_work_mem are set, my understanding is that the vacuum and autovacuum sessions should be limited to use the memory limits set by these parameters. But I am seeing more memory being used than these limits by autovacuum sessions, any reason why this would happen?
Please see below examples, where maintenance_work_mem is set to 20mb and shared_buffers is 128mb. When I see the memory for this session in top, it shows 162mb. But when default_statistics_target is increased to 3000, the session usage is 463mb, which is way more than 20mb maintenance_work_mem and 128mb shared_buffer. Shouldn't the process memory be capped to 20+128mb?
postgres=# show maintenance_work_mem ; maintenance_work_mem
---------------------- 20MB
(1 row)
postgres=# vacuum analyze mdm_context;
VACUUM
postgres=# show shared_buffers; shared_buffers
---------------- 128MB
(1 row)
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 62246 postgres 20 0 422892 165996 139068 R 57.1 15.7 25:06.34 postgres: postgres postgres [local] VACUUM
postgres=# show default_statistics_target; default_statistics_target
--------------------------- 100
(1 row)
postgres=# set default_statistics_target=3000;
SET
postgres=# vacuum analyze mdm_context;
VACUUM
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 62246 postgres 20 0 876132 474384 2976 R 62.9 47.6 25:11.41 postgres: postgres postgres [local] VACUUM
But when default_statistics_target is increased to 3000, the session usage is 463mb
‘The largest statistics target among the columns being analyzed determines the number of table rows sampled to prepare the statistics. Increasing the target causes a proportional increase in the time and space needed to do ANALYZE
.”David J.
On Sun, 1 Aug 2021 at 10:27, Ayub M <hiayub@gmail.com> wrote:
>
> Hello, when maintenance_work_mem and autovacuum_work_mem are set, my understanding is that the vacuum and autovacuum sessions should be limited to use the memory limits set by these parameters. But I am seeing more memory being used than these limits by autovacuum sessions, any reason why this would happen?
>
> Please see below examples, where maintenance_work_mem is set to 20mb and shared_buffers is 128mb. When I see the memory for this session in top, it shows 162mb. But when default_statistics_target is increased to 3000, the session usage is 463mb, which is way more than 20mb maintenance_work_mem and 128mb shared_buffer. Shouldn't the process memory be capped to 20+128mb?
>
>
> postgres=# show maintenance_work_mem ;
> maintenance_work_mem
> ----------------------
> 20MB
> (1 row)
> postgres=# vacuum analyze mdm_context;
> VACUUM
> postgres=# show shared_buffers;
> shared_buffers
> ----------------
> 128MB
> (1 row)
>
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 62246 postgres 20 0 422892 165996 139068 R 57.1 15.7 25:06.34 postgres: postgres postgres [local] VACUUM
>
your assumption may be right, but i am not sure of the interpretation from top.
"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
On Sun, 1 Aug 2021 at 10:27, Ayub M <hiayub@gmail.com> wrote:
>
> Hello, when maintenance_work_mem and autovacuum_work_mem are set, my understanding is that the vacuum and autovacuum sessions should be limited to use the memory limits set by these parameters. But I am seeing more memory being used than these limits by autovacuum sessions, any reason why this would happen?
>
> Please see below examples, where maintenance_work_mem is set to 20mb and shared_buffers is 128mb. When I see the memory for this session in top, it shows 162mb. But when default_statistics_target is increased to 3000, the session usage is 463mb, which is way more than 20mb maintenance_work_mem and 128mb shared_buffer. Shouldn't the process memory be capped to 20+128mb?
>
>
> postgres=# show maintenance_work_mem ;
> maintenance_work_mem
> ----------------------
> 20MB
> (1 row)
> postgres=# vacuum analyze mdm_context;
> VACUUM
> postgres=# show shared_buffers;
> shared_buffers
> ----------------
> 128MB
> (1 row)
>
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 62246 postgres 20 0 422892 165996 139068 R 57.1 15.7 25:06.34 postgres: postgres postgres [local] VACUUM
>
your assumption may be right, but i am not sure of the interpretation from top.I have to admit I am not great at understanding top output (RES vs VIRT) in general when it comes to limits.