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

Commit24c928a

Browse files
reindexdb: Allow specifying objects to process in all databases.
Presently, reindexdb's --table, --schema, --index, and --systemoptions cannot be used together with --all, i.e., you cannotspecify objects to process in all databases. This commit removesthis unnecessary restriction. Furthermore, it removes therestriction that --system cannot be used with --table, --schema,and --index. There is no such restriction for the latter options,and there is no technical reason to disallow these combinations.Reviewed-by: Kyotaro Horiguchi, Dean RasheedDiscussion:https://postgr.es/m/20230628232402.GA1954626%40nathanxps13
1 parent3d8652c commit24c928a

File tree

4 files changed

+110
-76
lines changed

4 files changed

+110
-76
lines changed

‎doc/src/sgml/ref/reindexdb.sgml

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,22 @@ PostgreSQL documentation
5555
</arg>
5656
</arg>
5757

58-
<arg choice="opt"><replaceable>dbname</replaceable></arg>
59-
</cmdsynopsis>
60-
61-
<cmdsynopsis>
62-
<command>reindexdb</command>
63-
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
64-
<arg rep="repeat"><replaceable>option</replaceable></arg>
65-
66-
<group choice="plain">
67-
<arg choice="plain"><option>-a</option></arg>
68-
<arg choice="plain"><option>--all</option></arg>
69-
</group>
70-
</cmdsynopsis>
71-
72-
<cmdsynopsis>
73-
<command>reindexdb</command>
74-
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
75-
<arg rep="repeat"><replaceable>option</replaceable></arg>
58+
<arg choice="plain">
59+
<arg choice="opt">
60+
<group choice="plain">
61+
<arg choice="plain"><option>-s</option></arg>
62+
<arg choice="plain"><option>--system</option></arg>
63+
</group>
64+
</arg>
65+
</arg>
7666

77-
<group choice="plain">
78-
<arg choice="plain"><option>-s</option></arg>
79-
<arg choice="plain"><option>--system</option></arg>
80-
</group>
81-
<arg choice="opt"><replaceable>dbname</replaceable></arg>
67+
<arg choice="opt">
68+
<group choice="plain">
69+
<arg choice="plain"><replaceable>dbname</replaceable></arg>
70+
<arg choice="plain"><option>-a</option></arg>
71+
<arg choice="plain"><option>--all</option></arg>
72+
</group>
73+
</arg>
8274
</cmdsynopsis>
8375
</refsynopsisdiv>
8476

‎src/bin/scripts/reindexdb.c

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ static void reindex_one_database(ConnParams *cparams, ReindexType type,
4646
staticvoidreindex_all_databases(ConnParams*cparams,
4747
constchar*progname,boolecho,
4848
boolquiet,boolverbose,boolconcurrently,
49-
intconcurrentCons,constchar*tablespace);
49+
intconcurrentCons,constchar*tablespace,
50+
boolsyscatalog,SimpleStringList*schemas,
51+
SimpleStringList*tables,
52+
SimpleStringList*indexes);
5053
staticvoidrun_reindex_command(PGconn*conn,ReindexTypetype,
5154
constchar*name,boolecho,boolverbose,
5255
boolconcurrently,boolasync,
@@ -203,62 +206,33 @@ main(int argc, char *argv[])
203206

204207
setup_cancel_handler(NULL);
205208

209+
if (concurrentCons>1)
210+
{
211+
/*
212+
* Index-level REINDEX is not supported with multiple jobs as we
213+
* cannot control the concurrent processing of multiple indexes
214+
* depending on the same relation.
215+
*/
216+
if (indexes.head!=NULL)
217+
pg_fatal("cannot use multiple jobs to reindex indexes");
218+
219+
if (syscatalog)
220+
pg_fatal("cannot use multiple jobs to reindex system catalogs");
221+
}
222+
206223
if (alldb)
207224
{
208225
if (dbname)
209226
pg_fatal("cannot reindex all databases and a specific one at the same time");
210-
if (syscatalog)
211-
pg_fatal("cannot reindex all databases and system catalogs at the same time");
212-
if (schemas.head!=NULL)
213-
pg_fatal("cannot reindex specific schema(s) in all databases");
214-
if (tables.head!=NULL)
215-
pg_fatal("cannot reindex specific table(s) in all databases");
216-
if (indexes.head!=NULL)
217-
pg_fatal("cannot reindex specific index(es) in all databases");
218227

219228
cparams.dbname=maintenance_db;
220229

221230
reindex_all_databases(&cparams,progname,echo,quiet,verbose,
222-
concurrently,concurrentCons,tablespace);
223-
}
224-
elseif (syscatalog)
225-
{
226-
if (schemas.head!=NULL)
227-
pg_fatal("cannot reindex specific schema(s) and system catalogs at the same time");
228-
if (tables.head!=NULL)
229-
pg_fatal("cannot reindex specific table(s) and system catalogs at the same time");
230-
if (indexes.head!=NULL)
231-
pg_fatal("cannot reindex specific index(es) and system catalogs at the same time");
232-
233-
if (concurrentCons>1)
234-
pg_fatal("cannot use multiple jobs to reindex system catalogs");
235-
236-
if (dbname==NULL)
237-
{
238-
if (getenv("PGDATABASE"))
239-
dbname=getenv("PGDATABASE");
240-
elseif (getenv("PGUSER"))
241-
dbname=getenv("PGUSER");
242-
else
243-
dbname=get_user_name_or_exit(progname);
244-
}
245-
246-
cparams.dbname=dbname;
247-
248-
reindex_one_database(&cparams,REINDEX_SYSTEM,NULL,
249-
progname,echo,verbose,
250-
concurrently,1,tablespace);
231+
concurrently,concurrentCons,tablespace,
232+
syscatalog,&schemas,&tables,&indexes);
251233
}
252234
else
253235
{
254-
/*
255-
* Index-level REINDEX is not supported with multiple jobs as we
256-
* cannot control the concurrent processing of multiple indexes
257-
* depending on the same relation.
258-
*/
259-
if (concurrentCons>1&&indexes.head!=NULL)
260-
pg_fatal("cannot use multiple jobs to reindex indexes");
261-
262236
if (dbname==NULL)
263237
{
264238
if (getenv("PGDATABASE"))
@@ -271,6 +245,11 @@ main(int argc, char *argv[])
271245

272246
cparams.dbname=dbname;
273247

248+
if (syscatalog)
249+
reindex_one_database(&cparams,REINDEX_SYSTEM,NULL,
250+
progname,echo,verbose,
251+
concurrently,1,tablespace);
252+
274253
if (schemas.head!=NULL)
275254
reindex_one_database(&cparams,REINDEX_SCHEMA,&schemas,
276255
progname,echo,verbose,
@@ -287,10 +266,11 @@ main(int argc, char *argv[])
287266
concurrently,concurrentCons,tablespace);
288267

289268
/*
290-
* reindex database only if neither index nor table nor schemais
291-
* specified
269+
* reindex database only if neither index nor table nor schemanor
270+
*system catalogs isspecified
292271
*/
293-
if (indexes.head==NULL&&tables.head==NULL&&schemas.head==NULL)
272+
if (!syscatalog&&indexes.head==NULL&&
273+
tables.head==NULL&&schemas.head==NULL)
294274
reindex_one_database(&cparams,REINDEX_DATABASE,NULL,
295275
progname,echo,verbose,
296276
concurrently,concurrentCons,tablespace);
@@ -711,7 +691,9 @@ static void
711691
reindex_all_databases(ConnParams*cparams,
712692
constchar*progname,boolecho,boolquiet,boolverbose,
713693
boolconcurrently,intconcurrentCons,
714-
constchar*tablespace)
694+
constchar*tablespace,boolsyscatalog,
695+
SimpleStringList*schemas,SimpleStringList*tables,
696+
SimpleStringList*indexes)
715697
{
716698
PGconn*conn;
717699
PGresult*result;
@@ -735,9 +717,35 @@ reindex_all_databases(ConnParams *cparams,
735717

736718
cparams->override_dbname=dbname;
737719

738-
reindex_one_database(cparams,REINDEX_DATABASE,NULL,
739-
progname,echo,verbose,concurrently,
740-
concurrentCons,tablespace);
720+
if (syscatalog)
721+
reindex_one_database(cparams,REINDEX_SYSTEM,NULL,
722+
progname,echo,verbose,
723+
concurrently,1,tablespace);
724+
725+
if (schemas->head!=NULL)
726+
reindex_one_database(cparams,REINDEX_SCHEMA,schemas,
727+
progname,echo,verbose,
728+
concurrently,concurrentCons,tablespace);
729+
730+
if (indexes->head!=NULL)
731+
reindex_one_database(cparams,REINDEX_INDEX,indexes,
732+
progname,echo,verbose,
733+
concurrently,1,tablespace);
734+
735+
if (tables->head!=NULL)
736+
reindex_one_database(cparams,REINDEX_TABLE,tables,
737+
progname,echo,verbose,
738+
concurrently,concurrentCons,tablespace);
739+
740+
/*
741+
* reindex database only if neither index nor table nor schema nor
742+
* system catalogs is specified
743+
*/
744+
if (!syscatalog&&indexes->head==NULL&&
745+
tables->head==NULL&&schemas->head==NULL)
746+
reindex_one_database(cparams,REINDEX_DATABASE,NULL,
747+
progname,echo,verbose,
748+
concurrently,concurrentCons,tablespace);
741749
}
742750

743751
PQclear(result);

‎src/bin/scripts/t/090_reindexdb.pl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,18 @@
262262
['reindexdb','-j','2','--concurrently','-d','postgres' ],
263263
'parallel reindexdb on database, concurrently');
264264

265+
# combinations of objects
266+
$node->issues_sql_like(
267+
['reindexdb','-s','-t','test1','postgres' ],
268+
qr/statement:\REINDEX SYSTEM postgres;/,
269+
'specify both --system and --table');
270+
$node->issues_sql_like(
271+
['reindexdb','-s','-i','test1x','postgres' ],
272+
qr/statement:\REINDEX INDEX public.test1x;/,
273+
'specify both --system and --index');
274+
$node->issues_sql_like(
275+
['reindexdb','-s','-S','pg_catalog','postgres' ],
276+
qr/statement:\REINDEX SCHEMA pg_catalog;/,
277+
'specify both --system and --schema');
278+
265279
done_testing();

‎src/bin/scripts/t/091_reindexdb_all.pl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,30 @@
1313

1414
$ENV{PGOPTIONS} ='--client-min-messages=WARNING';
1515

16+
$node->safe_psql('postgres',
17+
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a);');
18+
$node->safe_psql('template1',
19+
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a);');
1620
$node->issues_sql_like(
1721
['reindexdb','-a' ],
1822
qr/statement: REINDEX.*statement: REINDEX/s,
1923
'reindex all databases');
24+
$node->issues_sql_like(
25+
['reindexdb','-a','-s' ],
26+
qr/statement: REINDEX SYSTEM postgres/s,
27+
'reindex system catalogs in all databases');
28+
$node->issues_sql_like(
29+
['reindexdb','-a','-S','public' ],
30+
qr/statement: REINDEX SCHEMA public/s,
31+
'reindex schema in all databases');
32+
$node->issues_sql_like(
33+
['reindexdb','-a','-i','test1x' ],
34+
qr/statement: REINDEX INDEX public\.test1x/s,
35+
'reindex index in all databases');
36+
$node->issues_sql_like(
37+
['reindexdb','-a','-t','test1' ],
38+
qr/statement: REINDEX TABLE public\.test1/s,
39+
'reindex table in all databases');
2040

2141
$node->safe_psql(
2242
'postgres',q(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp