Skip to content

Commit ae78cae

Browse files
committed
Add --buffer-usage-limit option to vacuumdb
1cbbee0 added BUFFER_USAGE_LIMIT to the VACUUM and ANALYZE commands, so here we permit that option to be specified in vacuumdb. In passing, adjust the documents for vacuum_buffer_usage_limit and the BUFFER_USAGE_LIMIT VACUUM option to mention "kB" rather than "KB". Do the same for the ERROR message in ExecVacuum() and check_vacuum_buffer_usage_limit(). Without that we might tell a user that the valid minimum value is 128 KB only to reject that because we accept only "kB" and not "KB". Also, add a small reminder comment in vacuum.h to try to trigger the memory of anyone adding new fields to VacuumParams that they might want to consider if vacuumdb needs to grow a new option too. Author: Melanie Plageman Reviewed-by: Justin Pryzby Reviewed-by: David Rowley Discussion: https://postgr.es/m/ZAzTg3iEnubscvbf@telsasoft.com
1 parent 00d1e02 commit ae78cae

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

doc/src/sgml/config.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,10 +2015,10 @@ include_dir 'conf.d'
20152015
used by the <command>VACUUM</command> and <command>ANALYZE</command>
20162016
commands. A setting of <literal>0</literal> will allow the operation
20172017
to use any number of <varname>shared_buffers</varname>. Otherwise
2018-
valid sizes range from <literal>128 KB</literal> to
2018+
valid sizes range from <literal>128 kB</literal> to
20192019
<literal>16 GB</literal>. If the specified size would exceed 1/8 the
20202020
size of <varname>shared_buffers</varname>, the size is silently capped
2021-
to that value. The default value is <literal>256 KB</literal>. If
2021+
to that value. The default value is <literal>256 kB</literal>. If
20222022
this value is specified without units, it is taken as kilobytes. This
20232023
parameter can be set at any time. It can be overridden for
20242024
<xref linkend="sql-vacuum"/> and <xref linkend="sql-analyze"/>

doc/src/sgml/ref/vacuumdb.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,19 @@ PostgreSQL documentation
278278
</listitem>
279279
</varlistentry>
280280

281+
<varlistentry>
282+
<term><option>--buffer-usage-limit <replaceable class="parameter">buffer_usage_limit</replaceable></option></term>
283+
<listitem>
284+
<para>
285+
Specifies the
286+
<glossterm linkend="glossary-buffer-access-strategy">Buffer Access Strategy</glossterm>
287+
ring buffer size for a given invocation of <application>vacuumdb</application>.
288+
This size is used to calculate the number of shared buffers which will
289+
be reused as part of this strategy. See <xref linkend="sql-vacuum"/>.
290+
</para>
291+
</listitem>
292+
</varlistentry>
293+
281294
<varlistentry>
282295
<term><option>-n <replaceable class="parameter">schema</replaceable></option></term>
283296
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>

src/backend/commands/vacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ check_vacuum_buffer_usage_limit(int *newval, void **extra,
135135
return true;
136136

137137
/* Value does not fall within any allowable range */
138-
GUC_check_errdetail("\"vacuum_buffer_usage_limit\" must be 0 or between %d KB and %d KB",
138+
GUC_check_errdetail("\"vacuum_buffer_usage_limit\" must be 0 or between %d kB and %d kB",
139139
MIN_BAS_VAC_RING_SIZE_KB, MAX_BAS_VAC_RING_SIZE_KB);
140140

141141
return false;
@@ -225,7 +225,7 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
225225
{
226226
ereport(ERROR,
227227
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
228-
errmsg("buffer_usage_limit option must be 0 or between %d KB and %d KB",
228+
errmsg("buffer_usage_limit option must be 0 or between %d kB and %d kB",
229229
MIN_BAS_VAC_RING_SIZE_KB, MAX_BAS_VAC_RING_SIZE_KB)));
230230
}
231231

src/bin/scripts/vacuumdb.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct vacuumingOptions
4646
bool process_main;
4747
bool process_toast;
4848
bool skip_database_stats;
49+
char *buffer_usage_limit;
4950
} vacuumingOptions;
5051

5152
/* object filter options */
@@ -123,6 +124,7 @@ main(int argc, char *argv[])
123124
{"no-truncate", no_argument, NULL, 10},
124125
{"no-process-toast", no_argument, NULL, 11},
125126
{"no-process-main", no_argument, NULL, 12},
127+
{"buffer-usage-limit", required_argument, NULL, 13},
126128
{NULL, 0, NULL, 0}
127129
};
128130

@@ -147,6 +149,7 @@ main(int argc, char *argv[])
147149
/* initialize options */
148150
memset(&vacopts, 0, sizeof(vacopts));
149151
vacopts.parallel_workers = -1;
152+
vacopts.buffer_usage_limit = NULL;
150153
vacopts.no_index_cleanup = false;
151154
vacopts.force_index_cleanup = false;
152155
vacopts.do_truncate = true;
@@ -266,6 +269,9 @@ main(int argc, char *argv[])
266269
case 12:
267270
vacopts.process_main = false;
268271
break;
272+
case 13:
273+
vacopts.buffer_usage_limit = pg_strdup(optarg);
274+
break;
269275
default:
270276
/* getopt_long already emitted a complaint */
271277
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -343,6 +349,14 @@ main(int argc, char *argv[])
343349
pg_fatal("cannot use the \"%s\" option with the \"%s\" option",
344350
"no-index-cleanup", "force-index-cleanup");
345351

352+
/*
353+
* buffer-usage-limit is not allowed with VACUUM FULL unless ANALYZE is
354+
* included too.
355+
*/
356+
if (vacopts.buffer_usage_limit && vacopts.full && !vacopts.and_analyze)
357+
pg_fatal("cannot use the \"%s\" option with the \"%s\" option",
358+
"buffer-usage-limit", "full");
359+
346360
/* fill cparams except for dbname, which is set below */
347361
cparams.pghost = host;
348362
cparams.pgport = port;
@@ -550,6 +564,10 @@ vacuum_one_database(ConnParams *cparams,
550564
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
551565
"--parallel", "13");
552566

567+
if (vacopts->buffer_usage_limit && PQserverVersion(conn) < 160000)
568+
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
569+
"--buffer-usage-limit", "16");
570+
553571
/* skip_database_stats is used automatically if server supports it */
554572
vacopts->skip_database_stats = (PQserverVersion(conn) >= 160000);
555573

@@ -1048,6 +1066,13 @@ prepare_vacuum_command(PQExpBuffer sql, int serverVersion,
10481066
vacopts->parallel_workers);
10491067
sep = comma;
10501068
}
1069+
if (vacopts->buffer_usage_limit)
1070+
{
1071+
Assert(serverVersion >= 160000);
1072+
appendPQExpBuffer(sql, "%sBUFFER_USAGE_LIMIT '%s'", sep,
1073+
vacopts->buffer_usage_limit);
1074+
sep = comma;
1075+
}
10511076
if (sep != paren)
10521077
appendPQExpBufferChar(sql, ')');
10531078
}
@@ -1111,6 +1136,7 @@ help(const char *progname)
11111136
printf(_(" --force-index-cleanup always remove index entries that point to dead tuples\n"));
11121137
printf(_(" -j, --jobs=NUM use this many concurrent connections to vacuum\n"));
11131138
printf(_(" --min-mxid-age=MXID_AGE minimum multixact ID age of tables to vacuum\n"));
1139+
printf(_(" --buffer-usage-limit=BUFSIZE size of ring buffer used for vacuum\n"));
11141140
printf(_(" --min-xid-age=XID_AGE minimum transaction ID age of tables to vacuum\n"));
11151141
printf(_(" --no-index-cleanup don't remove index entries that point to dead tuples\n"));
11161142
printf(_(" --no-process-main skip the main relation\n"));

src/include/commands/vacuum.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ typedef enum VacOptValue
213213
*
214214
* Note that at least one of VACOPT_VACUUM and VACOPT_ANALYZE must be set
215215
* in options.
216+
*
217+
* When adding a new VacuumParam member, consider adding it to vacuumdb as
218+
* well.
216219
*/
217220
typedef struct VacuumParams
218221
{

src/test/regress/expected/vacuum.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ VACUUM (BUFFER_USAGE_LIMIT 0) vac_option_tab;
358358
ANALYZE (BUFFER_USAGE_LIMIT 0) vac_option_tab;
359359
-- value exceeds max size error
360360
VACUUM (BUFFER_USAGE_LIMIT 16777220) vac_option_tab;
361-
ERROR: buffer_usage_limit option must be 0 or between 128 KB and 16777216 KB
361+
ERROR: buffer_usage_limit option must be 0 or between 128 kB and 16777216 kB
362362
-- value is less than min size error
363363
VACUUM (BUFFER_USAGE_LIMIT 120) vac_option_tab;
364-
ERROR: buffer_usage_limit option must be 0 or between 128 KB and 16777216 KB
364+
ERROR: buffer_usage_limit option must be 0 or between 128 kB and 16777216 kB
365365
-- integer overflow error
366366
VACUUM (BUFFER_USAGE_LIMIT 10000000000) vac_option_tab;
367367
ERROR: value: "10000000000": is invalid for buffer_usage_limit

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy