Skip to content

Commit 1b49d56

Browse files
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
1 parent 5fb4cea commit 1b49d56

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

doc/src/sgml/ref/clusterdb.sgml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PostgreSQL documentation
2323
<cmdsynopsis>
2424
<command>clusterdb</command>
2525
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
26-
<group choice="opt"><arg choice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group>
26+
<arg rep="repeat"><replaceable>option</replaceable></arg>
2727

2828
<arg choice="plain" rep="repeat">
2929
<arg choice="opt">
@@ -35,14 +35,13 @@ PostgreSQL documentation
3535
</arg>
3636
</arg>
3737

38-
<arg choice="opt"><replaceable>dbname</replaceable></arg>
39-
</cmdsynopsis>
40-
41-
<cmdsynopsis>
42-
<command>clusterdb</command>
43-
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
44-
<group choice="opt"><arg choice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group>
45-
<group choice="plain"><arg choice="plain"><option>--all</option></arg><arg choice="plain"><option>-a</option></arg></group>
38+
<arg choice="opt">
39+
<group choice="plain">
40+
<arg choice="plain"><replaceable>dbname</replaceable></arg>
41+
<arg choice="plain"><option>-a</option></arg>
42+
<arg choice="plain"><option>--all</option></arg>
43+
</group>
44+
</arg>
4645
</cmdsynopsis>
4746
</refsynopsisdiv>
4847

src/bin/scripts/clusterdb.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121

2222
static void cluster_one_database(const ConnParams *cparams, const char *table,
2323
const char *progname, bool verbose, bool echo);
24-
static void cluster_all_databases(ConnParams *cparams, const char *progname,
25-
bool verbose, bool echo, bool quiet);
24+
static void cluster_all_databases(ConnParams *cparams, SimpleStringList *tables,
25+
const char *progname, bool verbose, bool echo,
26+
bool quiet);
2627
static void help(const char *progname);
2728

2829

@@ -147,12 +148,10 @@ main(int argc, char *argv[])
147148
if (dbname)
148149
pg_fatal("cannot cluster all databases and a specific one at the same time");
149150

150-
if (tables.head != NULL)
151-
pg_fatal("cannot cluster specific table(s) in all databases");
152-
153151
cparams.dbname = maintenance_db;
154152

155-
cluster_all_databases(&cparams, progname, verbose, echo, quiet);
153+
cluster_all_databases(&cparams, &tables,
154+
progname, verbose, echo, quiet);
156155
}
157156
else
158157
{
@@ -226,8 +225,9 @@ cluster_one_database(const ConnParams *cparams, const char *table,
226225

227226

228227
static void
229-
cluster_all_databases(ConnParams *cparams, const char *progname,
230-
bool verbose, bool echo, bool quiet)
228+
cluster_all_databases(ConnParams *cparams, SimpleStringList *tables,
229+
const char *progname, bool verbose, bool echo,
230+
bool quiet)
231231
{
232232
PGconn *conn;
233233
PGresult *result;
@@ -251,7 +251,17 @@ cluster_all_databases(ConnParams *cparams, const char *progname,
251251

252252
cparams->override_dbname = dbname;
253253

254-
cluster_one_database(cparams, NULL, progname, verbose, echo);
254+
if (tables->head != NULL)
255+
{
256+
SimpleStringListCell *cell;
257+
258+
for (cell = tables->head; cell; cell = cell->next)
259+
cluster_one_database(cparams, cell->val,
260+
progname, verbose, echo);
261+
}
262+
else
263+
cluster_one_database(cparams, NULL,
264+
progname, verbose, echo);
255265
}
256266

257267
PQclear(result);

src/bin/scripts/t/011_clusterdb_all.pl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@
3333
qr/FATAL: cannot connect to invalid database "regression_invalid"/,
3434
'clusterdb cannot target invalid database');
3535

36+
$node->safe_psql('postgres',
37+
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
38+
);
39+
$node->safe_psql('template1',
40+
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
41+
);
42+
$node->issues_sql_like(
43+
[ 'clusterdb', '-a', '-t', 'test1' ],
44+
qr/statement: CLUSTER public\.test1/s,
45+
'cluster specific table in all databases');
46+
3647
done_testing();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy