@@ -46,7 +46,10 @@ static void reindex_one_database(ConnParams *cparams, ReindexType type,
46
46
static void reindex_all_databases (ConnParams * cparams ,
47
47
const char * progname , bool echo ,
48
48
bool quiet , bool verbose , bool concurrently ,
49
- int concurrentCons , const char * tablespace );
49
+ int concurrentCons , const char * tablespace ,
50
+ bool syscatalog , SimpleStringList * schemas ,
51
+ SimpleStringList * tables ,
52
+ SimpleStringList * indexes );
50
53
static void run_reindex_command (PGconn * conn , ReindexType type ,
51
54
const char * name , bool echo , bool verbose ,
52
55
bool concurrently , bool async ,
@@ -203,62 +206,33 @@ main(int argc, char *argv[])
203
206
204
207
setup_cancel_handler (NULL );
205
208
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
+
206
223
if (alldb )
207
224
{
208
225
if (dbname )
209
226
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" );
218
227
219
228
cparams .dbname = maintenance_db ;
220
229
221
230
reindex_all_databases (& cparams , progname , echo , quiet , verbose ,
222
- concurrently , concurrentCons , tablespace );
223
- }
224
- else if (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
- else if (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 );
251
233
}
252
234
else
253
235
{
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
-
262
236
if (dbname == NULL )
263
237
{
264
238
if (getenv ("PGDATABASE" ))
@@ -271,6 +245,11 @@ main(int argc, char *argv[])
271
245
272
246
cparams .dbname = dbname ;
273
247
248
+ if (syscatalog )
249
+ reindex_one_database (& cparams , REINDEX_SYSTEM , NULL ,
250
+ progname , echo , verbose ,
251
+ concurrently , 1 , tablespace );
252
+
274
253
if (schemas .head != NULL )
275
254
reindex_one_database (& cparams , REINDEX_SCHEMA , & schemas ,
276
255
progname , echo , verbose ,
@@ -287,10 +266,11 @@ main(int argc, char *argv[])
287
266
concurrently , concurrentCons , tablespace );
288
267
289
268
/*
290
- * reindex database only if neither index nor table nor schema is
291
- * specified
269
+ * reindex database only if neither index nor table nor schema nor
270
+ * system catalogs is specified
292
271
*/
293
- if (indexes .head == NULL && tables .head == NULL && schemas .head == NULL )
272
+ if (!syscatalog && indexes .head == NULL &&
273
+ tables .head == NULL && schemas .head == NULL )
294
274
reindex_one_database (& cparams , REINDEX_DATABASE , NULL ,
295
275
progname , echo , verbose ,
296
276
concurrently , concurrentCons , tablespace );
@@ -711,7 +691,9 @@ static void
711
691
reindex_all_databases (ConnParams * cparams ,
712
692
const char * progname , bool echo , bool quiet , bool verbose ,
713
693
bool concurrently , int concurrentCons ,
714
- const char * tablespace )
694
+ const char * tablespace , bool syscatalog ,
695
+ SimpleStringList * schemas , SimpleStringList * tables ,
696
+ SimpleStringList * indexes )
715
697
{
716
698
PGconn * conn ;
717
699
PGresult * result ;
@@ -735,9 +717,35 @@ reindex_all_databases(ConnParams *cparams,
735
717
736
718
cparams -> override_dbname = dbname ;
737
719
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 );
741
749
}
742
750
743
751
PQclear (result );
0 commit comments