Lower minimum maintenance_work_mem to 64kB
authorJohn Naylor <john.naylor@postgresql.org>
Tue, 6 Aug 2024 13:38:33 +0000 (20:38 +0700)
committerJohn Naylor <john.naylor@postgresql.org>
Sat, 10 Aug 2024 07:52:56 +0000 (14:52 +0700)
Since the introduction of TID store, vacuum uses far less memory in
the common case than in versions 16 and earlier. Invoking multiple
rounds of index vacuuming in turn requires a much larger table. It'd
be a good idea anyway to cover this case in regression testing, and a
lower limit is less painful for slow buildfarm animals. The reason to
do it now is to re-enable coverage of the bugfix in commit 83c39a1f7f.

For consistency, give autovacuum_work_mem the same treatment.

Suggested by Andres Freund
Tested by Melanie Plageman
Backpatch to v17, where TID store was introduced

Discussion: https://postgr.es/m/20240516205458.ohvlzis5b5tvejru@awork3.anarazel.de
Discussion: https://postgr.es/m/20240722164745.fvaoh6g6zprisqgp%40awork3.anarazel.de

src/backend/postmaster/autovacuum.c
src/backend/utils/misc/guc_tables.c
src/backend/utils/misc/postgresql.conf.sample

index 4e4a0ccbefbedda9bd7b763de54311c69f553f74..7d0877c95ec87cbc46bd5ca89443c033cd16127e 100644 (file)
@@ -3339,12 +3339,12 @@ check_autovacuum_work_mem(int *newval, void **extra, GucSource source)
        return true;
 
    /*
-    * We clamp manually-set values to at least 1MB.  Since
+    * We clamp manually-set values to at least 64kB.  Since
     * maintenance_work_mem is always set to at least this value, do the same
     * here.
     */
-   if (*newval < 1024)
-       *newval = 1024;
+   if (*newval < 64)
+       *newval = 64;
 
    return true;
 }
index c0a52cdcc3ed24b5d2810a0eaf3430ac256b6968..289dea7878a6dbb2e932e56ffcbd4cf9e5aba060 100644 (file)
@@ -2510,6 +2510,11 @@ struct config_int ConfigureNamesInt[] =
        NULL, NULL, NULL
    },
 
+   /*
+    * Dynamic shared memory has a higher overhead than local memory contexts,
+    * so when testing low-memory scenarios that could use shared memory, the
+    * recommended minimum is 1MB.
+    */
    {
        {"maintenance_work_mem", PGC_USERSET, RESOURCES_MEM,
            gettext_noop("Sets the maximum memory to be used for maintenance operations."),
@@ -2517,7 +2522,7 @@ struct config_int ConfigureNamesInt[] =
            GUC_UNIT_KB
        },
        &maintenance_work_mem,
-       65536, 1024, MAX_KILOBYTES,
+       65536, 64, MAX_KILOBYTES,
        NULL, NULL, NULL
    },
 
index 9ec9f97e926dc08fa5ec4f7b31e860679f8ea7f7..667e0dc40a24f72ee7b4c02a13b7d7798c5888a6 100644 (file)
 # you actively intend to use prepared transactions.
 #work_mem = 4MB                # min 64kB
 #hash_mem_multiplier = 2.0     # 1-1000.0 multiplier on hash table work_mem
-#maintenance_work_mem = 64MB       # min 1MB
-#autovacuum_work_mem = -1      # min 1MB, or -1 to use maintenance_work_mem
+#maintenance_work_mem = 64MB       # min 64kB
+#autovacuum_work_mem = -1      # min 64kB, or -1 to use maintenance_work_mem
 #logical_decoding_work_mem = 64MB  # min 64kB
 #max_stack_depth = 2MB         # min 100kB
 #shared_memory_type = mmap     # the default is the first option