From 1b49d56d358a9c2e310d66c0ac87216d9b932b78 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 11 Mar 2024 13:11:20 -0500 Subject: clusterdb: Allow specifying tables to process in all databases. Presently, clusterdb's --table option cannot be used together with --all, i.e., you cannot specify tables to process in all databases. This commit removes this unnecessary restriction. In passing, change the synopsis in the documentation to use "[option...]" instead of "[--verbose | -v]". There are other general-purpose options (e.g., --quiet and --echo), but the synopsis currently only lists --verbose. Reviewed-by: Kyotaro Horiguchi, Dean Rasheed Discussion: https://postgr.es/m/20230628232402.GA1954626%40nathanxps13 --- src/bin/scripts/clusterdb.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/bin/scripts/clusterdb.c') diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 1f3aec1b5e1..3503a3bb584 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -21,8 +21,9 @@ static void cluster_one_database(const ConnParams *cparams, const char *table, const char *progname, bool verbose, bool echo); -static void cluster_all_databases(ConnParams *cparams, const char *progname, - bool verbose, bool echo, bool quiet); +static void cluster_all_databases(ConnParams *cparams, SimpleStringList *tables, + const char *progname, bool verbose, bool echo, + bool quiet); static void help(const char *progname); @@ -147,12 +148,10 @@ main(int argc, char *argv[]) if (dbname) pg_fatal("cannot cluster all databases and a specific one at the same time"); - if (tables.head != NULL) - pg_fatal("cannot cluster specific table(s) in all databases"); - cparams.dbname = maintenance_db; - cluster_all_databases(&cparams, progname, verbose, echo, quiet); + cluster_all_databases(&cparams, &tables, + progname, verbose, echo, quiet); } else { @@ -226,8 +225,9 @@ cluster_one_database(const ConnParams *cparams, const char *table, static void -cluster_all_databases(ConnParams *cparams, const char *progname, - bool verbose, bool echo, bool quiet) +cluster_all_databases(ConnParams *cparams, SimpleStringList *tables, + const char *progname, bool verbose, bool echo, + bool quiet) { PGconn *conn; PGresult *result; @@ -251,7 +251,17 @@ cluster_all_databases(ConnParams *cparams, const char *progname, cparams->override_dbname = dbname; - cluster_one_database(cparams, NULL, progname, verbose, echo); + if (tables->head != NULL) + { + SimpleStringListCell *cell; + + for (cell = tables->head; cell; cell = cell->next) + cluster_one_database(cparams, cell->val, + progname, verbose, echo); + } + else + cluster_one_database(cparams, NULL, + progname, verbose, echo); } PQclear(result); -- cgit v1.2.3