@@ -219,6 +219,7 @@ static bool analyze = true;
219
219
static bool alldb = false;
220
220
static bool noorder = false;
221
221
static SimpleStringList table_list = {NULL , NULL };
222
+ static SimpleStringList schema_list = {NULL , NULL };
222
223
static char * orderby = NULL ;
223
224
static char * tablespace = NULL ;
224
225
static bool moveidx = false;
@@ -239,6 +240,7 @@ static pgut_option options[] =
239
240
{
240
241
{ 'b' , 'a' , "all" , & alldb },
241
242
{ 'l' , 't' , "table" , & table_list },
243
+ { 'l' , 'c' , "schema" , & schema_list },
242
244
{ 'b' , 'n' , "no-order" , & noorder },
243
245
{ 's' , 'o' , "order-by" , & orderby },
244
246
{ 's' , 's' , "tablespace" , & tablespace },
@@ -312,6 +314,10 @@ main(int argc, char *argv[])
312
314
ereport (ERROR ,
313
315
(errcode (EINVAL ),
314
316
errmsg ("cannot repack specific table(s) in all databases" )));
317
+ if (schema_list .head )
318
+ ereport (ERROR ,
319
+ (errcode (EINVAL ),
320
+ errmsg ("cannot repack specific schema(s) in all databases" )));
315
321
repack_all_databases (orderby );
316
322
}
317
323
else
@@ -555,12 +561,14 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
555
561
const char * * params = NULL ;
556
562
int iparam = 0 ;
557
563
size_t num_tables ;
564
+ size_t num_schemas ;
558
565
size_t num_params ;
559
566
560
567
num_tables = simple_string_list_size (table_list );
568
+ num_schemas = simple_string_list_size (schema_list );
561
569
562
570
/* 1st param is the user-specified tablespace */
563
- num_params = num_tables + 1 ;
571
+ num_params = num_tables + num_schemas + 1 ;
564
572
params = pgut_malloc (num_params * sizeof (char * ));
565
573
566
574
initStringInfo (& sql );
@@ -596,6 +604,19 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
596
604
}
597
605
appendStringInfoString (& sql , ")" );
598
606
}
607
+ else if (num_schemas )
608
+ {
609
+ appendStringInfoString (& sql , "schemaname IN (" );
610
+ for (cell = schema_list .head ; cell ; cell = cell -> next )
611
+ {
612
+ /* Construct schema name placeholders to be used by PQexecParams */
613
+ appendStringInfo (& sql , "$%d" , iparam + 1 );
614
+ params [iparam ++ ] = cell -> val ;
615
+ if (cell -> next )
616
+ appendStringInfoString (& sql , ", " );
617
+ }
618
+ appendStringInfoString (& sql , ")" );
619
+ }
599
620
else
600
621
{
601
622
appendStringInfoString (& sql , "pkid IS NOT NULL" );
@@ -1895,6 +1916,7 @@ pgut_help(bool details)
1895
1916
printf ("Options:\n" );
1896
1917
printf (" -a, --all repack all databases\n" );
1897
1918
printf (" -t, --table=TABLE repack specific table only\n" );
1919
+ printf (" -c, --schema=SCHEMA repack specific schema only\n" );
1898
1920
printf (" -s, --tablespace=TBLSPC move repacked tables to a new tablespace\n" );
1899
1921
printf (" -S, --moveidx move repacked indexes to TBLSPC too\n" );
1900
1922
printf (" -o, --order-by=COLUMNS order by columns instead of cluster keys\n" );
0 commit comments