Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b49d56

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-purposeoptions (e.g., --quiet and --echo), but the synopsis currently onlylists --verbose.Reviewed-by: Kyotaro Horiguchi, Dean RasheedDiscussion:https://postgr.es/m/20230628232402.GA1954626%40nathanxps13
1 parent5fb4cea commit1b49d56

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"><argchoice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group>
26+
<argrep="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
staticvoidcluster_one_database(constConnParams*cparams,constchar*table,
2323
constchar*progname,boolverbose,boolecho);
24-
staticvoidcluster_all_databases(ConnParams*cparams,constchar*progname,
25-
boolverbose,boolecho,boolquiet);
24+
staticvoidcluster_all_databases(ConnParams*cparams,SimpleStringList*tables,
25+
constchar*progname,boolverbose,boolecho,
26+
boolquiet);
2627
staticvoidhelp(constchar*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
staticvoid
229-
cluster_all_databases(ConnParams*cparams,constchar*progname,
230-
boolverbose,boolecho,boolquiet)
228+
cluster_all_databases(ConnParams*cparams,SimpleStringList*tables,
229+
constchar*progname,boolverbose,boolecho,
230+
boolquiet)
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)

[8]ページ先頭

©2009-2025 Movatter.jp