@@ -37,6 +37,8 @@ typedef struct vacuumingOptions
37
37
int min_mxid_age ;
38
38
int parallel_workers ; /* >= 0 indicates user specified the
39
39
* parallel degree, otherwise -1 */
40
+ bool do_index_cleanup ;
41
+ bool do_truncate ;
40
42
} vacuumingOptions ;
41
43
42
44
@@ -96,6 +98,8 @@ main(int argc, char *argv[])
96
98
{"skip-locked" , no_argument , NULL , 5 },
97
99
{"min-xid-age" , required_argument , NULL , 6 },
98
100
{"min-mxid-age" , required_argument , NULL , 7 },
101
+ {"no-index-cleanup" , no_argument , NULL , 8 },
102
+ {"no-truncate" , no_argument , NULL , 9 },
99
103
{NULL , 0 , NULL , 0 }
100
104
};
101
105
@@ -117,9 +121,11 @@ main(int argc, char *argv[])
117
121
int concurrentCons = 1 ;
118
122
int tbl_count = 0 ;
119
123
120
- /* initialize options to all false */
124
+ /* initialize options */
121
125
memset (& vacopts , 0 , sizeof (vacopts ));
122
126
vacopts .parallel_workers = -1 ;
127
+ vacopts .do_index_cleanup = true;
128
+ vacopts .do_truncate = true;
123
129
124
130
pg_logging_init (argv [0 ]);
125
131
progname = get_progname (argv [0 ]);
@@ -223,6 +229,12 @@ main(int argc, char *argv[])
223
229
exit (1 );
224
230
}
225
231
break ;
232
+ case 8 :
233
+ vacopts .do_index_cleanup = false;
234
+ break ;
235
+ case 9 :
236
+ vacopts .do_truncate = false;
237
+ break ;
226
238
default :
227
239
fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
228
240
exit (1 );
@@ -267,6 +279,18 @@ main(int argc, char *argv[])
267
279
"disable-page-skipping" );
268
280
exit (1 );
269
281
}
282
+ if (!vacopts .do_index_cleanup )
283
+ {
284
+ pg_log_error ("cannot use the \"%s\" option when performing only analyze" ,
285
+ "no-index-cleanup" );
286
+ exit (1 );
287
+ }
288
+ if (!vacopts .do_truncate )
289
+ {
290
+ pg_log_error ("cannot use the \"%s\" option when performing only analyze" ,
291
+ "no-truncate" );
292
+ exit (1 );
293
+ }
270
294
/* allow 'and_analyze' with 'analyze_only' */
271
295
}
272
296
@@ -412,6 +436,22 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
412
436
exit (1 );
413
437
}
414
438
439
+ if (!vacopts -> do_index_cleanup && PQserverVersion (conn ) < 120000 )
440
+ {
441
+ PQfinish (conn );
442
+ pg_log_error ("cannot use the \"%s\" option on server versions older than PostgreSQL %s" ,
443
+ "no-index-cleanup" , "12" );
444
+ exit (1 );
445
+ }
446
+
447
+ if (!vacopts -> do_truncate && PQserverVersion (conn ) < 120000 )
448
+ {
449
+ PQfinish (conn );
450
+ pg_log_error ("cannot use the \"%s\" option on server versions older than PostgreSQL %s" ,
451
+ "no-truncate" , "12" );
452
+ exit (1 );
453
+ }
454
+
415
455
if (vacopts -> skip_locked && PQserverVersion (conn ) < 120000 )
416
456
{
417
457
PQfinish (conn );
@@ -832,6 +872,20 @@ prepare_vacuum_command(PQExpBuffer sql, int serverVersion,
832
872
appendPQExpBuffer (sql , "%sDISABLE_PAGE_SKIPPING" , sep );
833
873
sep = comma ;
834
874
}
875
+ if (!vacopts -> do_index_cleanup )
876
+ {
877
+ /* INDEX_CLEANUP is supported since v12 */
878
+ Assert (serverVersion >= 120000 );
879
+ appendPQExpBuffer (sql , "%sINDEX_CLEANUP FALSE" , sep );
880
+ sep = comma ;
881
+ }
882
+ if (!vacopts -> do_truncate )
883
+ {
884
+ /* TRUNCATE is supported since v12 */
885
+ Assert (serverVersion >= 120000 );
886
+ appendPQExpBuffer (sql , "%sTRUNCATE FALSE" , sep );
887
+ sep = comma ;
888
+ }
835
889
if (vacopts -> skip_locked )
836
890
{
837
891
/* SKIP_LOCKED is supported since v12 */
@@ -930,6 +984,8 @@ help(const char *progname)
930
984
printf (_ (" -j, --jobs=NUM use this many concurrent connections to vacuum\n" ));
931
985
printf (_ (" --min-mxid-age=MXID_AGE minimum multixact ID age of tables to vacuum\n" ));
932
986
printf (_ (" --min-xid-age=XID_AGE minimum transaction ID age of tables to vacuum\n" ));
987
+ printf (_ (" --no-index-cleanup don't remove index entries that point to dead tuples\n" ));
988
+ printf (_ (" --no-truncate don't truncate empty pages at the end of the table\n" ));
933
989
printf (_ (" -P, --parallel=PARALLEL_DEGREE use this many background workers for vacuum, if available\n" ));
934
990
printf (_ (" -q, --quiet don't write any messages\n" ));
935
991
printf (_ (" --skip-locked skip relations that cannot be immediately locked\n" ));
0 commit comments