Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8693559

Browse files
New autovacuum_work_mem parameter
If autovacuum_work_mem is set, autovacuum workers now usethis parameter in preference to maintenance_work_mem.Peter Geoghegan
1 parent36da3cf commit8693559

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-10
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,26 @@ include 'filename'
11981198
</para>
11991199
<para>
12001200
Note that when autovacuum runs, up to
1201-
<xref linkend="guc-autovacuum-max-workers"> times this memory may be
1202-
allocated, so be careful not to set the default value too high.
1201+
<xref linkend="guc-autovacuum-max-workers"> times this memory
1202+
may be allocated, so be careful not to set the default value
1203+
too high. It may be useful to control for this by separately
1204+
setting <xref linkend="guc-autovacuum-work-mem">.
1205+
</para>
1206+
</listitem>
1207+
</varlistentry>
1208+
1209+
<varlistentry id="guc-autovacuum-work-mem" xreflabel="autovacuum_work_mem">
1210+
<term><varname>autovacuum_work_mem</varname> (<type>integer</type>)</term>
1211+
<indexterm>
1212+
<primary><varname>autovacuum_work_mem</> configuration parameter</primary>
1213+
</indexterm>
1214+
<listitem>
1215+
<para>
1216+
Specifies the maximum amount of memory to be used by each
1217+
autovacuum worker process. It defaults to -1, indicating that
1218+
the value of <xref linkend="guc-maintenance-work-mem"> should
1219+
be used instead. The setting has no effect on the behavior of
1220+
<command>VACUUM</command> when run in other contexts.
12031221
</para>
12041222
</listitem>
12051223
</varlistentry>

‎src/backend/commands/vacuumlazy.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
* relations with finite memory space usage. To do that, we set upper bounds
1111
* on the number of tuples and pages we will keep track of at once.
1212
*
13-
* We are willing to use at most maintenance_work_memmemory space to keep
14-
*track of dead tuples. We initially allocate an arrayofTIDs of that size,
15-
*withanupper limit that depends on tablesize (this limit ensures we don't
16-
*allocate a huge area uselessly for vacuuming small tables).If the array
17-
*threatens to overflow, we suspend the heap scan phase and perform a pass of
18-
*index cleanup and page compaction, then resume the heap scan with an empty
19-
* TID array.
13+
* We are willing to use at most maintenance_work_mem(or perhaps
14+
*autovacuum_work_mem) memory space to keep trackofdead tuples. We
15+
*initially allocateanarray of TIDs of thatsize, with an upper limit that
16+
*depends on table size (this limit ensures we don't allocate a huge area
17+
*uselessly for vacuuming small tables). If the array threatens to overflow,
18+
*we suspend the heap scan phase and perform a pass of index cleanup and page
19+
*compaction, then resume the heap scan with an emptyTID array.
2020
*
2121
* If we're processing a table with no indexes, we can just vacuum each page
2222
* as we go; there's no need to save up multiple tuples to minimize the number
@@ -1599,10 +1599,13 @@ static void
15991599
lazy_space_alloc(LVRelStats*vacrelstats,BlockNumberrelblocks)
16001600
{
16011601
longmaxtuples;
1602+
intvac_work_mem=IsAutoVacuumWorkerProcess()&&
1603+
autovacuum_work_mem!=-1 ?
1604+
autovacuum_work_mem :maintenance_work_mem;
16021605

16031606
if (vacrelstats->hasindex)
16041607
{
1605-
maxtuples= (maintenance_work_mem*1024L) /sizeof(ItemPointerData);
1608+
maxtuples= (vac_work_mem*1024L) /sizeof(ItemPointerData);
16061609
maxtuples=Min(maxtuples,INT_MAX);
16071610
maxtuples=Min(maxtuples,MaxAllocSize /sizeof(ItemPointerData));
16081611

‎src/backend/postmaster/autovacuum.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
*/
111111
boolautovacuum_start_daemon= false;
112112
intautovacuum_max_workers;
113+
intautovacuum_work_mem=-1;
113114
intautovacuum_naptime;
114115
intautovacuum_vac_thresh;
115116
doubleautovacuum_vac_scale;

‎src/backend/utils/misc/guc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static const char *show_tcp_keepalives_count(void);
194194
staticboolcheck_maxconnections(int*newval,void**extra,GucSourcesource);
195195
staticboolcheck_max_worker_processes(int*newval,void**extra,GucSourcesource);
196196
staticboolcheck_autovacuum_max_workers(int*newval,void**extra,GucSourcesource);
197+
staticboolcheck_autovacuum_work_mem(int*newval,void**extra,GucSourcesource);
197198
staticboolcheck_effective_io_concurrency(int*newval,void**extra,GucSourcesource);
198199
staticvoidassign_effective_io_concurrency(intnewval,void*extra);
199200
staticvoidassign_pgstat_temp_directory(constchar*newval,void*extra);
@@ -2357,6 +2358,17 @@ static struct config_int ConfigureNamesInt[] =
23572358
check_autovacuum_max_workers,NULL,NULL
23582359
},
23592360

2361+
{
2362+
{"autovacuum_work_mem",PGC_SIGHUP,RESOURCES_MEM,
2363+
gettext_noop("Sets the maximum memory to be used by each autovacuum worker process."),
2364+
NULL,
2365+
GUC_UNIT_KB
2366+
},
2367+
&autovacuum_work_mem,
2368+
-1,-1,MAX_KILOBYTES,
2369+
check_autovacuum_work_mem,NULL,NULL
2370+
},
2371+
23602372
{
23612373
{"tcp_keepalives_idle",PGC_USERSET,CLIENT_CONN_OTHER,
23622374
gettext_noop("Time between issuing TCP keepalives."),
@@ -8777,6 +8789,29 @@ check_autovacuum_max_workers(int *newval, void **extra, GucSource source)
87778789
return true;
87788790
}
87798791

8792+
staticbool
8793+
check_autovacuum_work_mem(int*newval,void**extra,GucSourcesource)
8794+
{
8795+
/*
8796+
* -1 indicates fallback.
8797+
*
8798+
* If we haven't yet changed the boot_val default of -1, just let it be.
8799+
* Autovacuum will look to maintenance_work_mem instead.
8800+
*/
8801+
if (*newval==-1)
8802+
return true;
8803+
8804+
/*
8805+
* We clamp manually-set values to at least 1MB. Since
8806+
* maintenance_work_mem is always set to at least this value, do the same
8807+
* here.
8808+
*/
8809+
if (*newval<1024)
8810+
*newval=1024;
8811+
8812+
return true;
8813+
}
8814+
87808815
staticbool
87818816
check_max_worker_processes(int*newval,void**extra,GucSourcesource)
87828817
{

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
# actively intend to use prepared transactions.
125125
#work_mem = 1MB# min 64kB
126126
#maintenance_work_mem = 16MB# min 1MB
127+
#autovacuum_work_mem = -1# min 1MB, or -1 to use maintenance_work_mem
127128
#max_stack_depth = 2MB# min 100kB
128129
#dynamic_shared_memory_type = posix # the default is the first option
129130
# supported by the operating system:

‎src/include/postmaster/autovacuum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/* GUC variables */
1919
externboolautovacuum_start_daemon;
2020
externintautovacuum_max_workers;
21+
externintautovacuum_work_mem;
2122
externintautovacuum_naptime;
2223
externintautovacuum_vac_thresh;
2324
externdoubleautovacuum_vac_scale;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp