use PostgresNode;
use TestLib;
-use Test::More tests => 44;
+use Test::More tests => 49;
program_help_ok('vacuumdb');
program_version_ok('vacuumdb');
$node->command_fails(
[ 'vacuumdb', '--analyze-only', '--disable-page-skipping', 'postgres' ],
'--analyze-only and --disable-page-skipping specified together');
+$node->issues_sql_like(
+ [ 'vacuumdb', '-P', 2, 'postgres' ],
+ qr/statement: VACUUM \(PARALLEL 2\).*;/,
+ 'vacuumdb -P 2');
+$node->issues_sql_like(
+ [ 'vacuumdb', '-P', 0, 'postgres' ],
+ qr/statement: VACUUM \(PARALLEL 0\).*;/,
+ 'vacuumdb -P 0');
$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
'vacuumdb with connection string');
$node->command_fails(
[ 'vacuumdb', '--analyze', '--table', 'vactable(c)', 'postgres' ],
'incorrect column name with ANALYZE');
+$node->command_fails(
+ [ 'vacuumdb', '-P', -1, 'postgres' ],
+ 'negative parallel degree');
$node->issues_sql_like(
[ 'vacuumdb', '--analyze', '--table', 'vactable(a, b)', 'postgres' ],
qr/statement: VACUUM \(ANALYZE\) public.vactable\(a, b\);/,
bool skip_locked;
int min_xid_age;
int min_mxid_age;
+ int parallel_workers; /* >= 0 indicates user specified the
+ * parallel degree, otherwise -1 */
} vacuumingOptions;
{"full", no_argument, NULL, 'f'},
{"verbose", no_argument, NULL, 'v'},
{"jobs", required_argument, NULL, 'j'},
+ {"parallel", required_argument, NULL, 'P'},
{"maintenance-db", required_argument, NULL, 2},
{"analyze-in-stages", no_argument, NULL, 3},
{"disable-page-skipping", no_argument, NULL, 4},
/* initialize options to all false */
memset(&vacopts, 0, sizeof(vacopts));
+ vacopts.parallel_workers = -1;
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
handle_help_version_opts(argc, argv, "vacuumdb", help);
- while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fvj:", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fvj:P:", long_options, &optindex)) != -1)
{
switch (c)
{
exit(1);
}
break;
+ case 'P':
+ vacopts.parallel_workers = atoi(optarg);
+ if (vacopts.parallel_workers < 0)
+ {
+ pg_log_error("parallel vacuum degree must be a non-negative integer");
+ exit(1);
+ }
+ break;
case 2:
maintenance_db = pg_strdup(optarg);
break;
/* allow 'and_analyze' with 'analyze_only' */
}
+ /* Prohibit full and analyze_only options with parallel option */
+ if (vacopts.parallel_workers >= 0)
+ {
+ if (vacopts.analyze_only)
+ {
+ pg_log_error("cannot use the \"%s\" option when performing only analyze",
+ "parallel");
+ exit(1);
+ }
+ if (vacopts.full)
+ {
+ pg_log_error("cannot use the \"%s\" option when performing full",
+ "parallel");
+ exit(1);
+ }
+ }
+
setup_cancel_handler(NULL);
/* Avoid opening extra connections. */
exit(1);
}
+ if (vacopts->parallel_workers >= 0 && PQserverVersion(conn) < 130000)
+ {
+ pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
+ "--parallel", "13");
+ exit(1);
+ }
+
if (!quiet)
{
if (stage != ANALYZE_NO_STAGE)
appendPQExpBuffer(sql, "%sANALYZE", sep);
sep = comma;
}
+ if (vacopts->parallel_workers >= 0)
+ {
+ /* PARALLEL is supported since v13 */
+ Assert(serverVersion >= 130000);
+ appendPQExpBuffer(sql, "%sPARALLEL %d", sep,
+ vacopts->parallel_workers);
+ sep = comma;
+ }
if (sep != paren)
appendPQExpBufferChar(sql, ')');
}
printf(_(" -j, --jobs=NUM use this many concurrent connections to vacuum\n"));
printf(_(" --min-mxid-age=MXID_AGE minimum multixact ID age of tables to vacuum\n"));
printf(_(" --min-xid-age=XID_AGE minimum transaction ID age of tables to vacuum\n"));
+ printf(_(" -P, --parallel=PARALLEL_DEGREE use this many background workers for vacuum, if available\n"));
printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" --skip-locked skip relations that cannot be immediately locked\n"));
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table(s) only\n"));