if (optind < argc)
{
pg_log_error("too many command-line arguments (first is \"%s\")",
argv[optind]);
pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1);
}
if (vacopts.analyze_only)
{ if (vacopts.full)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "full"); if (vacopts.freeze)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "freeze"); if (vacopts.disable_page_skipping)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "disable-page-skipping"); if (vacopts.no_index_cleanup)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "no-index-cleanup"); if (vacopts.force_index_cleanup)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "force-index-cleanup"); if (!vacopts.do_truncate)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "no-truncate"); if (!vacopts.process_main)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "no-process-main"); if (!vacopts.process_toast)
pg_fatal("cannot use the \"%s\" option when performing only analyze", "no-process-toast"); /* 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_fatal("cannot use the \"%s\" option when performing only analyze", "parallel"); if (vacopts.full)
pg_fatal("cannot use the \"%s\" option when performing full vacuum", "parallel");
}
/* Prohibit --no-index-cleanup and --force-index-cleanup together */ if (vacopts.no_index_cleanup && vacopts.force_index_cleanup)
pg_fatal("cannot use the \"%s\" option with the \"%s\" option", "no-index-cleanup", "force-index-cleanup");
/* *buffer-usage-limitisnotallowedwithVACUUMFULLunlessANALYZEis *includedtoo.
*/ if (vacopts.buffer_usage_limit && vacopts.full && !vacopts.and_analyze)
pg_fatal("cannot use the \"%s\" option with the \"%s\" option", "buffer-usage-limit", "full");
/* *Prohibit--missing-stats-onlywithout--analyze-onlyor *--analyze-in-stages.
*/ if (vacopts.missing_stats_only && !vacopts.analyze_only)
pg_fatal("cannot use the \"%s\" option without \"%s\" or \"%s\"", "missing-stats-only", "analyze-only", "analyze-in-stages");
/* fill cparams except for dbname, which is set below */
cparams.pghost = host;
cparams.pgport = port;
cparams.pguser = username;
cparams.prompt_password = prompt_password;
cparams.override_dbname = NULL;
setup_cancel_handler(NULL);
/* Avoid opening extra connections. */ if (tbl_count && (concurrentCons > tbl_count))
concurrentCons = tbl_count;
if (objfilter & OBJFILTER_ALL_DBS)
{
cparams.dbname = maintenance_db;
/* *Verifythatthefiltersusedatcommandlinearecompatible.
*/ void
check_objfilter(void)
{ if ((objfilter & OBJFILTER_ALL_DBS) &&
(objfilter & OBJFILTER_DATABASE))
pg_fatal("cannot vacuum all databases and a specific one at the same time");
if ((objfilter & OBJFILTER_TABLE) &&
(objfilter & OBJFILTER_SCHEMA))
pg_fatal("cannot vacuum all tables in schema(s) and specific table(s) at the same time");
if ((objfilter & OBJFILTER_TABLE) &&
(objfilter & OBJFILTER_SCHEMA_EXCLUDE))
pg_fatal("cannot vacuum specific table(s) and exclude schema(s) at the same time");
if ((objfilter & OBJFILTER_SCHEMA) &&
(objfilter & OBJFILTER_SCHEMA_EXCLUDE))
pg_fatal("cannot vacuum all tables in schema(s) and exclude schema(s) at the same time");
}
if (vacopts->disable_page_skipping && PQserverVersion(conn) < 90600)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "disable-page-skipping", "9.6");
}
if (vacopts->no_index_cleanup && PQserverVersion(conn) < 120000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "no-index-cleanup", "12");
}
if (vacopts->force_index_cleanup && PQserverVersion(conn) < 120000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "force-index-cleanup", "12");
}
if (!vacopts->do_truncate && PQserverVersion(conn) < 120000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "no-truncate", "12");
}
if (!vacopts->process_main && PQserverVersion(conn) < 160000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "no-process-main", "16");
}
if (!vacopts->process_toast && PQserverVersion(conn) < 140000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "no-process-toast", "14");
}
if (vacopts->skip_locked && PQserverVersion(conn) < 120000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "skip-locked", "12");
}
if (vacopts->min_xid_age != 0 && PQserverVersion(conn) < 90600)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "--min-xid-age", "9.6");
}
if (vacopts->min_mxid_age != 0 && PQserverVersion(conn) < 90600)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "--min-mxid-age", "9.6");
}
if (vacopts->parallel_workers >= 0 && PQserverVersion(conn) < 130000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "--parallel", "13");
}
if (vacopts->buffer_usage_limit && PQserverVersion(conn) < 160000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "--buffer-usage-limit", "16");
}
if (vacopts->missing_stats_only && PQserverVersion(conn) < 150000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "--missing-stats-only", "15");
}
/* skip_database_stats is used automatically if server supports it */
vacopts->skip_database_stats = (PQserverVersion(conn) >= 160000);
if (!ParallelSlotsWaitCompletion(sa))
{
failed = true; goto finish;
}
/* If we used SKIP_DATABASE_STATS, mop up with ONLY_DATABASE_STATS */ if (vacopts->skip_database_stats && stage == ANALYZE_NO_STAGE)
{ constchar *cmd = "VACUUM (ONLY_DATABASE_STATS);";
ParallelSlot *free_slot = ParallelSlotsGetIdle(sa, NULL);
/* *Usedtomatchthetablesorschemaslistedbytheuser,fortheWHERE *clause.
*/ if (objects_listed)
{ if (objfilter & OBJFILTER_SCHEMA_EXCLUDE)
appendPQExpBufferStr(&catalog_query, " AND listed_objects.object_oid IS NULL\n"); else
appendPQExpBufferStr(&catalog_query, " AND listed_objects.object_oid IS NOT NULL\n");
}
/* *Ifnotableswerelisted,filterfortherelevantrelationtypes.If *tablesweregivenvia--table,don'tbotherfilteringbyrelationtype. *Instead,lettheserverdecidewhetheragivenrelationcanbe *processedinwhichcasetheuserwillknowaboutit.
*/ if ((objfilter & OBJFILTER_TABLE) == 0)
{
appendPQExpBufferStr(&catalog_query, " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
CppAsString2(RELKIND_RELATION) ", "
CppAsString2(RELKIND_MATVIEW) "])\n");
}
/* *For--min-xid-ageand--min-mxid-age,theageoftherelationisthe *greatestoftheagesofthemainrelationanditsassociatedTOAST *table.ThecommandsgeneratedbyvacuumdbwillalsoprocesstheTOAST *tablefortherelationifnecessary,soitdoesnotneedtobe *consideredseparately.
*/ if (vacopts->min_xid_age != 0)
{
appendPQExpBuffer(&catalog_query, " AND GREATEST(pg_catalog.age(c.relfrozenxid)," " pg_catalog.age(t.relfrozenxid)) " " OPERATOR(pg_catalog.>=) '%d'::pg_catalog.int4\n" " AND c.relfrozenxid OPERATOR(pg_catalog.!=)" " '0'::pg_catalog.xid\n",
vacopts->min_xid_age);
}
if (vacopts->min_mxid_age != 0)
{
appendPQExpBuffer(&catalog_query, " AND GREATEST(pg_catalog.mxid_age(c.relminmxid)," " pg_catalog.mxid_age(t.relminmxid)) OPERATOR(pg_catalog.>=)" " '%d'::pg_catalog.int4\n" " AND c.relminmxid OPERATOR(pg_catalog.!=)" " '0'::pg_catalog.xid\n",
vacopts->min_mxid_age);
}
if (vacopts->missing_stats_only)
{
appendPQExpBufferStr(&catalog_query, " AND (\n");
/* regular stats */
appendPQExpBufferStr(&catalog_query, " EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " WHERE a.attrelid OPERATOR(pg_catalog.=) c.oid\n" " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" " AND NOT a.attisdropped\n" " AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND a.attgenerated OPERATOR(pg_catalog.<>) "
CppAsString2(ATTRIBUTE_GENERATED_VIRTUAL) "\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic s\n" " WHERE s.starelid OPERATOR(pg_catalog.=) a.attrelid\n" " AND s.staattnum OPERATOR(pg_catalog.=) a.attnum\n" " AND s.stainherit OPERATOR(pg_catalog.=) p.inherited))\n");
/* extended stats */
appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext e\n" " WHERE e.stxrelid OPERATOR(pg_catalog.=) c.oid\n" " AND e.stxstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext_data d\n" " WHERE d.stxoid OPERATOR(pg_catalog.=) e.oid\n" " AND d.stxdinherit OPERATOR(pg_catalog.=) p.inherited))\n");
/* expression indexes */
appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " JOIN pg_catalog.pg_index i" " ON i.indexrelid OPERATOR(pg_catalog.=) a.attrelid\n" " WHERE i.indrelid OPERATOR(pg_catalog.=) c.oid\n" " AND i.indkey[a.attnum OPERATOR(pg_catalog.-) 1::pg_catalog.int2]" " OPERATOR(pg_catalog.=) 0::pg_catalog.int2\n" " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" " AND NOT a.attisdropped\n" " AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic s\n" " WHERE s.starelid OPERATOR(pg_catalog.=) a.attrelid\n" " AND s.staattnum OPERATOR(pg_catalog.=) a.attnum\n" " AND s.stainherit OPERATOR(pg_catalog.=) p.inherited))\n");
/* inheritance and regular stats */
appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " WHERE a.attrelid OPERATOR(pg_catalog.=) c.oid\n" " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" " AND NOT a.attisdropped\n" " AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND a.attgenerated OPERATOR(pg_catalog.<>) "
CppAsString2(ATTRIBUTE_GENERATED_VIRTUAL) "\n" " AND c.relhassubclass\n" " AND NOT p.inherited\n" " AND EXISTS (SELECT NULL FROM pg_catalog.pg_inherits h\n" " WHERE h.inhparent OPERATOR(pg_catalog.=) c.oid)\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic s\n" " WHERE s.starelid OPERATOR(pg_catalog.=) a.attrelid\n" " AND s.staattnum OPERATOR(pg_catalog.=) a.attnum\n" " AND s.stainherit))\n");
/* inheritance and extended stats */
appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext e\n" " WHERE e.stxrelid OPERATOR(pg_catalog.=) c.oid\n" " AND e.stxstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND c.relhassubclass\n" " AND NOT p.inherited\n" " AND EXISTS (SELECT NULL FROM pg_catalog.pg_inherits h\n" " WHERE h.inhparent OPERATOR(pg_catalog.=) c.oid)\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext_data d\n" " WHERE d.stxoid OPERATOR(pg_catalog.=) e.oid\n" " AND d.stxdinherit))\n");
appendPQExpBufferStr(&catalog_query, " )\n");
}
/* *Executethecatalogquery.Weusethedefaultsearch_pathforthis *queryforconsistencywithtablelookupsdoneelsewherebytheuser.
*/
appendPQExpBufferStr(&catalog_query, " ORDER BY c.relpages DESC;");
executeCommand(conn, "RESET search_path;", echo);
res = executeQuery(conn, catalog_query.data, echo);
termPQExpBuffer(&catalog_query);
PQclear(executeQuery(conn, ALWAYS_SECURE_SEARCH_PATH_SQL, echo));
/* *Buildqualifiedidentifiersforeachtable,includingthecolumnlist *ifgiven.
*/
initPQExpBuffer(&buf); for (int i = 0; i < PQntuples(res); i++)
{
appendPQExpBufferStr(&buf,
fmtQualifiedIdEnc(PQgetvalue(res, i, 1),
PQgetvalue(res, i, 0),
PQclientEncoding(conn)));
if (objects_listed && !PQgetisnull(res, i, 2))
appendPQExpBufferStr(&buf, PQgetvalue(res, i, 2));
conn = connectMaintenanceDatabase(cparams, progname, echo);
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn AND datconnlimit <> -2 ORDER BY 1;",
echo);
PQfinish(conn);
if (analyze_in_stages)
{
SimpleStringList **found_objs = NULL;
if (vacopts->missing_stats_only)
found_objs = palloc0(PQntuples(result) * sizeof(SimpleStringList *));
/* *Whenanalyzingalldatabasesinstages,weanalyzethemallinthe *fasteststagefirst,sothatinitialstatisticsbecomeavailable *forallofthemassoonaspossible. * *Thismeansweestablishseveraltimesasmanyconnections,but *that'sasecondaryconsideration.
*/ for (stage = 0; stage < ANALYZE_NUM_STAGES; stage++)
{ for (i = 0; i < PQntuples(result); i++)
{
cparams->override_dbname = PQgetvalue(result, i, 0);
vacuum_one_database(cparams, vacopts,
stage,
objects,
vacopts->missing_stats_only ? &found_objs[i] : NULL,
concurrentCons,
progname, echo, quiet);
}
}
} else
{ for (i = 0; i < PQntuples(result); i++)
{
cparams->override_dbname = PQgetvalue(result, i, 0);
if (!status)
{ if (table)
pg_log_error("vacuuming of table \"%s\" in database \"%s\" failed: %s",
table, PQdb(conn), PQerrorMessage(conn)); else
pg_log_error("vacuuming of database \"%s\" failed: %s",
PQdb(conn), PQerrorMessage(conn));
}
}
staticvoid
help(constchar *progname)
{
printf(_("%s cleans and analyzes a PostgreSQL database.\n\n"), progname);
printf(_("Usage:\n"));
printf(_(" %s [OPTION]... [DBNAME]\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" -a, --all vacuum all databases\n"));
printf(_(" --buffer-usage-limit=SIZE size of ring buffer used for vacuum\n"));
printf(_(" -d, --dbname=DBNAME database to vacuum\n"));
printf(_(" --disable-page-skipping disable all page-skipping behavior\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -f, --full do full vacuuming\n"));
printf(_(" -F, --freeze freeze row transaction information\n"));
printf(_(" --force-index-cleanup always remove index entries that point to dead tuples\n"));
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(_(" --missing-stats-only only analyze relations with missing statistics\n"));
printf(_(" --no-index-cleanup don't remove index entries that point to dead tuples\n"));
printf(_(" --no-process-main skip the main relation\n"));
printf(_(" --no-process-toast skip the TOAST table associated with the table to vacuum\n"));
printf(_(" --no-truncate don't truncate empty pages at the end of the table\n"));
printf(_(" -n, --schema=SCHEMA vacuum tables in the specified schema(s) only\n"));
printf(_(" -N, --exclude-schema=SCHEMA do not vacuum tables in the specified schema(s)\n"));
printf(_(" -P, --parallel=PARALLEL_WORKERS 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"));
printf(_(" -v, --verbose write a lot of output\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -z, --analyze update optimizer statistics\n"));
printf(_(" -Z, --analyze-only only update optimizer statistics; no vacuum\n"));
printf(_(" --analyze-in-stages only update optimizer statistics, in multiple\n" " stages for faster results; no vacuum\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port\n"));
printf(_(" -U, --username=USERNAME user name to connect as\n"));
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt\n"));
printf(_(" --maintenance-db=DBNAME alternate maintenance database\n"));
printf(_("\nRead the description of the SQL command VACUUM for details.\n"));
printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.46 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Sekunden
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.