mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
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
This commit is contained in:
parent
5fb4cea1b4
commit
1b49d56d35
@ -23,7 +23,7 @@ PostgreSQL documentation
|
|||||||
<cmdsynopsis>
|
<cmdsynopsis>
|
||||||
<command>clusterdb</command>
|
<command>clusterdb</command>
|
||||||
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
|
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
|
||||||
<group choice="opt"><arg choice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group>
|
<arg rep="repeat"><replaceable>option</replaceable></arg>
|
||||||
|
|
||||||
<arg choice="plain" rep="repeat">
|
<arg choice="plain" rep="repeat">
|
||||||
<arg choice="opt">
|
<arg choice="opt">
|
||||||
@ -35,14 +35,13 @@ PostgreSQL documentation
|
|||||||
</arg>
|
</arg>
|
||||||
</arg>
|
</arg>
|
||||||
|
|
||||||
<arg choice="opt"><replaceable>dbname</replaceable></arg>
|
<arg choice="opt">
|
||||||
</cmdsynopsis>
|
<group choice="plain">
|
||||||
|
<arg choice="plain"><replaceable>dbname</replaceable></arg>
|
||||||
<cmdsynopsis>
|
<arg choice="plain"><option>-a</option></arg>
|
||||||
<command>clusterdb</command>
|
<arg choice="plain"><option>--all</option></arg>
|
||||||
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
|
</group>
|
||||||
<group choice="opt"><arg choice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group>
|
</arg>
|
||||||
<group choice="plain"><arg choice="plain"><option>--all</option></arg><arg choice="plain"><option>-a</option></arg></group>
|
|
||||||
</cmdsynopsis>
|
</cmdsynopsis>
|
||||||
</refsynopsisdiv>
|
</refsynopsisdiv>
|
||||||
|
|
||||||
|
@ -21,8 +21,9 @@
|
|||||||
|
|
||||||
static void cluster_one_database(const ConnParams *cparams, const char *table,
|
static void cluster_one_database(const ConnParams *cparams, const char *table,
|
||||||
const char *progname, bool verbose, bool echo);
|
const char *progname, bool verbose, bool echo);
|
||||||
static void cluster_all_databases(ConnParams *cparams, const char *progname,
|
static void cluster_all_databases(ConnParams *cparams, SimpleStringList *tables,
|
||||||
bool verbose, bool echo, bool quiet);
|
const char *progname, bool verbose, bool echo,
|
||||||
|
bool quiet);
|
||||||
static void help(const char *progname);
|
static void help(const char *progname);
|
||||||
|
|
||||||
|
|
||||||
@ -147,12 +148,10 @@ main(int argc, char *argv[])
|
|||||||
if (dbname)
|
if (dbname)
|
||||||
pg_fatal("cannot cluster all databases and a specific one at the same time");
|
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;
|
cparams.dbname = maintenance_db;
|
||||||
|
|
||||||
cluster_all_databases(&cparams, progname, verbose, echo, quiet);
|
cluster_all_databases(&cparams, &tables,
|
||||||
|
progname, verbose, echo, quiet);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -226,8 +225,9 @@ cluster_one_database(const ConnParams *cparams, const char *table,
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cluster_all_databases(ConnParams *cparams, const char *progname,
|
cluster_all_databases(ConnParams *cparams, SimpleStringList *tables,
|
||||||
bool verbose, bool echo, bool quiet)
|
const char *progname, bool verbose, bool echo,
|
||||||
|
bool quiet)
|
||||||
{
|
{
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
PGresult *result;
|
PGresult *result;
|
||||||
@ -251,7 +251,17 @@ cluster_all_databases(ConnParams *cparams, const char *progname,
|
|||||||
|
|
||||||
cparams->override_dbname = dbname;
|
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);
|
PQclear(result);
|
||||||
|
@ -33,4 +33,15 @@ $node->command_fails_like([ 'clusterdb', '-d', 'regression_invalid'],
|
|||||||
qr/FATAL: cannot connect to invalid database "regression_invalid"/,
|
qr/FATAL: cannot connect to invalid database "regression_invalid"/,
|
||||||
'clusterdb cannot target invalid database');
|
'clusterdb cannot target invalid database');
|
||||||
|
|
||||||
|
$node->safe_psql('postgres',
|
||||||
|
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
|
||||||
|
);
|
||||||
|
$node->safe_psql('template1',
|
||||||
|
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
|
||||||
|
);
|
||||||
|
$node->issues_sql_like(
|
||||||
|
[ 'clusterdb', '-a', '-t', 'test1' ],
|
||||||
|
qr/statement: CLUSTER public\.test1/s,
|
||||||
|
'cluster specific table in all databases');
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user