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);
}
/* 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);
if (concurrentCons > 1 && syscatalog)
pg_fatal("cannot use multiple jobs to reindex system catalogs");
if (alldb)
{ if (dbname)
pg_fatal("cannot reindex all databases and a specific one at the same time");
if (concurrently && PQserverVersion(conn) < 120000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "concurrently", "12");
}
if (tablespace && PQserverVersion(conn) < 140000)
{
PQfinish(conn);
pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", "tablespace", "14");
}
if (!parallel)
{ switch (process_type)
{ case REINDEX_DATABASE: case REINDEX_SYSTEM:
case REINDEX_INDEX: case REINDEX_SCHEMA: case REINDEX_TABLE:
process_list = user_list;
Assert(user_list != NULL); break;
}
} else
{ switch (process_type)
{ case REINDEX_SCHEMA:
Assert(user_list != NULL); /* fall through */
case REINDEX_DATABASE:
/* Build a list of relations from the database */
process_list = get_parallel_tables_list(conn, process_type,
user_list, echo);
process_type = REINDEX_TABLE;
/* Bail out if nothing to process */ if (process_list == NULL)
{
PQfinish(conn); return;
} break;
/* no need to continue if there are more elements than jobs */ if (items_count >= concurrentCons) break;
}
concurrentCons = Min(concurrentCons, items_count);
Assert(concurrentCons > 0);
if (sep != paren)
appendPQExpBufferStr(sql, ") ");
/* object type */ switch (type)
{ case REINDEX_DATABASE:
appendPQExpBufferStr(sql, "DATABASE "); break; case REINDEX_INDEX:
appendPQExpBufferStr(sql, "INDEX "); break; case REINDEX_SCHEMA:
appendPQExpBufferStr(sql, "SCHEMA "); break; case REINDEX_SYSTEM:
appendPQExpBufferStr(sql, "SYSTEM "); break; case REINDEX_TABLE:
appendPQExpBufferStr(sql, "TABLE "); break;
}
/* *ParenthesizedgrammarisonlysupportedforCONCURRENTLYsince *PostgreSQL14.Since12,CONCURRENTLYcanbespecifiedafterthe *objecttype.
*/ if (concurrently)
appendPQExpBufferStr(sql, "CONCURRENTLY ");
/* object name */ switch (type)
{ case REINDEX_DATABASE: case REINDEX_SYSTEM:
appendPQExpBufferStr(sql,
fmtIdEnc(name, PQclientEncoding(conn))); break; case REINDEX_INDEX: case REINDEX_TABLE:
appendQualifiedRelation(sql, name, conn, echo); break; case REINDEX_SCHEMA:
appendPQExpBufferStr(sql, name); break;
}
/* finish the query */
appendPQExpBufferChar(sql, ';');
}
if (!status)
{ switch (type)
{ case REINDEX_DATABASE:
pg_log_error("reindexing of database \"%s\" failed: %s",
PQdb(conn), PQerrorMessage(conn)); break; case REINDEX_INDEX:
pg_log_error("reindexing of index \"%s\" in database \"%s\" failed: %s",
name, PQdb(conn), PQerrorMessage(conn)); break; case REINDEX_SCHEMA:
pg_log_error("reindexing of schema \"%s\" in database \"%s\" failed: %s",
name, PQdb(conn), PQerrorMessage(conn)); break; case REINDEX_SYSTEM:
pg_log_error("reindexing of system catalogs in database \"%s\" failed: %s",
PQdb(conn), PQerrorMessage(conn)); break; case REINDEX_TABLE:
pg_log_error("reindexing of table \"%s\" in database \"%s\" failed: %s",
name, PQdb(conn), PQerrorMessage(conn)); break;
}
}
}
/* Build qualified identifiers for each table */ for (int i = 0; i < ntups; i++)
{
simple_string_list_append(tables,
fmtQualifiedIdEnc(PQgetvalue(res, i, 1),
PQgetvalue(res, i, 0),
PQclientEncoding(conn)));
}
PQclear(res);
/* *Wewantallindexesofthesametabletogether.Ordertablesbythe *sizeofitsgreatestindex.Withineachtable,orderindexesbysize.
*/
appendPQExpBufferStr(&catalog_query, "']::pg_catalog.regclass[])\n" "ORDER BY max(i.relpages) OVER \n" " (PARTITION BY x.indrelid),\n" " x.indrelid, i.relpages;\n");
/* Empty the original index_list to fill it from the query result. */
simple_string_list_destroy(index_list);
index_list->head = index_list->tail = NULL;
res = executeQuery(conn, catalog_query.data, echo);
termPQExpBuffer(&catalog_query);
/* *Buildtwolists,onewithtableOIDsandtheotherwithfully-qualified *indexnames.
*/ for (int i = 0; i < ntups; i++)
{
simple_oid_list_append(*table_list, atooid(PQgetvalue(res, i, 0)));
simple_string_list_append(index_list,
fmtQualifiedIdEnc(PQgetvalue(res, i, 1),
PQgetvalue(res, i, 2),
PQclientEncoding(conn)));
}
conn = connectMaintenanceDatabase(cparams, progname, echo);
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn AND datconnlimit <> -2 ORDER BY 1;",
echo);
PQfinish(conn);
for (i = 0; i < PQntuples(result); i++)
{ char *dbname = PQgetvalue(result, i, 0);
staticvoid
help(constchar *progname)
{
printf(_("%s reindexes a PostgreSQL database.\n\n"), progname);
printf(_("Usage:\n"));
printf(_(" %s [OPTION]... [DBNAME]\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" -a, --all reindex all databases\n"));
printf(_(" --concurrently reindex concurrently\n"));
printf(_(" -d, --dbname=DBNAME database to reindex\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -i, --index=INDEX recreate specific index(es) only\n"));
printf(_(" -j, --jobs=NUM use this many concurrent connections to reindex\n"));
printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" -s, --system reindex system catalogs only\n"));
printf(_(" -S, --schema=SCHEMA reindex specific schema(s) only\n"));
printf(_(" -t, --table=TABLE reindex specific table(s) only\n"));
printf(_(" --tablespace=TABLESPACE tablespace where indexes are rebuilt\n"));
printf(_(" -v, --verbose write a lot of output\n"));
printf(_(" -V, --version output version information, then exit\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 REINDEX 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
¤ 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.0.20Bemerkung:
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-07)
¤
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.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.