@@ -226,6 +226,7 @@ static SimpleStringList r_index = {NULL, NULL};
226
226
static bool only_indexes = false;
227
227
static int wait_timeout = 60 ; /* in seconds */
228
228
static int jobs = 0 ; /* number of concurrent worker conns. */
229
+ static bool dryrun = false;
229
230
230
231
/* buffer should have at least 11 bytes */
231
232
static char *
@@ -240,6 +241,7 @@ static pgut_option options[] =
240
241
{ 'b' , 'a' , "all" , & alldb },
241
242
{ 'l' , 't' , "table" , & table_list },
242
243
{ 'b' , 'n' , "no-order" , & noorder },
244
+ { 'b' , 'N' , "dry-run" , & dryrun },
243
245
{ 's' , 'o' , "order-by" , & orderby },
244
246
{ 's' , 's' , "tablespace" , & tablespace },
245
247
{ 'b' , 'S' , "moveidx" , & moveidx },
@@ -513,9 +515,12 @@ repack_all_databases(const char *orderby)
513
515
dbname = PQgetvalue (result , i , 0 );
514
516
515
517
elog (INFO , "repacking database \"%s\"" , dbname );
516
- ret = repack_one_database (orderby , errbuf , sizeof (errbuf ));
517
- if (!ret )
518
- elog (INFO , "database \"%s\" skipped: %s" , dbname , errbuf );
518
+ if (!dryrun )
519
+ {
520
+ ret = repack_one_database (orderby , errbuf , sizeof (errbuf ));
521
+ if (!ret )
522
+ elog (INFO , "database \"%s\" skipped: %s" , dbname , errbuf );
523
+ }
519
524
}
520
525
521
526
CLEARPGRES (result );
@@ -1018,6 +1023,9 @@ repack_one_table(const repack_table *table, const char *orderby)
1018
1023
elog (DEBUG2 , "sql_update : %s" , table -> sql_update );
1019
1024
elog (DEBUG2 , "sql_pop : %s" , table -> sql_pop );
1020
1025
1026
+ if (dryrun )
1027
+ return ;
1028
+
1021
1029
/*
1022
1030
* 1. Setup advisory lock and trigger on main table.
1023
1031
*/
@@ -1693,6 +1701,10 @@ repack_table_indexes(PGresult *index_details)
1693
1701
continue ;
1694
1702
}
1695
1703
1704
+ elog (INFO , "repacking index \"%s\".\"index_%u\"" , schema_name , index );
1705
+ if (dryrun )
1706
+ continue ;
1707
+
1696
1708
params [0 ] = utoa (index , buffer [0 ]);
1697
1709
res = execute ("SELECT repack.repack_indexdef($1, $2, $3, true)" , 3 ,
1698
1710
params );
@@ -1731,6 +1743,9 @@ repack_table_indexes(PGresult *index_details)
1731
1743
getstr (index_details , i , 0 ));
1732
1744
}
1733
1745
1746
+ if (dryrun )
1747
+ return true;
1748
+
1734
1749
/* If we did not successfully repack any indexes, e.g. because of some
1735
1750
* error affecting every CREATE INDEX attempt, don't waste time with
1736
1751
* the ACCESS EXCLUSIVE lock on the table, and return false.
@@ -1899,6 +1914,7 @@ pgut_help(bool details)
1899
1914
printf (" -S, --moveidx move repacked indexes to TBLSPC too\n" );
1900
1915
printf (" -o, --order-by=COLUMNS order by columns instead of cluster keys\n" );
1901
1916
printf (" -n, --no-order do vacuum full instead of cluster\n" );
1917
+ printf (" -N, --dry-run print what would have been repacked\n" );
1902
1918
printf (" -j, --jobs=NUM Use this many parallel jobs for each table\n" );
1903
1919
printf (" -i, --index=INDEX move only the specified index\n" );
1904
1920
printf (" -x, --only-indexes move only indexes of the specified table\n" );
0 commit comments