v3-0003-move-dry_run-test-inside-run_vacuum_command.patch
text/x-patch
Filename: v3-0003-move-dry_run-test-inside-run_vacuum_command.patch
Type: text/x-patch
Part: 2
Message:
Re: vacuumdb: add --dry-run
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v3-0003
Subject: move dry_run test inside run_vacuum_command()
| File | + | − |
|---|---|---|
| src/bin/scripts/vacuuming.c | 24 | 33 |
From 93130f08a24abef26001199ae17c8812f31df3e5 Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Wed, 19 Nov 2025 19:24:26 -0500
Subject: [PATCH v3 3/5] move dry_run test inside run_vacuum_command()
---
src/bin/scripts/vacuuming.c | 57 ++++++++++++++++---------------------
1 file changed, 24 insertions(+), 33 deletions(-)
diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c
index f1fa565679c..f52af273d7e 100644
--- a/src/bin/scripts/vacuuming.c
+++ b/src/bin/scripts/vacuuming.c
@@ -44,7 +44,7 @@ static void free_retrieved_objects(SimpleStringList *list);
static void prepare_vacuum_command(PGconn *conn, PQExpBuffer sql,
vacuumingOptions *vacopts, const char *table);
static void run_vacuum_command(ParallelSlot *free_slot, const char *sql,
- bool echo, const char *table);
+ bool echo, bool dry_run, const char *table);
/*
* Executes vacuum/analyze as indicated. Returns 0 if the plan is carried
@@ -378,25 +378,8 @@ vacuum_one_database(ConnParams *cparams,
prepare_vacuum_command(free_slot->connection, &sql,
vacopts, tabname);
- if (vacopts->dry_run)
- {
- /*
- * Print the command that we would have run in a real run,
- * the immediately mark the unused slot as free again.
- */
- printf("not executed: %s\n", sql.data);
- free_slot->inUse = false;
- }
- else
- {
- /*
- * Execute the vacuum. All errors are handled in processQueryResult
- * through ParallelSlotsGetIdle.
- */
- ParallelSlotSetHandler(free_slot, TableCommandResultHandler, NULL);
- run_vacuum_command(free_slot, sql.data,
- echo, tabname);
- }
+ run_vacuum_command(free_slot, sql.data,
+ echo, vacopts->dry_run, tabname);
cell = cell->next;
} while (cell != NULL);
@@ -419,19 +402,10 @@ vacuum_one_database(ConnParams *cparams,
goto finish;
}
- if (vacopts->dry_run)
- {
- printf("not executed: %s\n", cmd);
- free_slot->inUse = false;
- }
- else
- {
- ParallelSlotSetHandler(free_slot, TableCommandResultHandler, NULL);
- run_vacuum_command(free_slot, cmd, echo, NULL);
+ run_vacuum_command(free_slot, cmd, echo, vacopts->dry_run, NULL);
- if (!ParallelSlotsWaitCompletion(sa))
- ret = EXIT_FAILURE; /* error already reported by handler */
- }
+ if (!ParallelSlotsWaitCompletion(sa))
+ ret = EXIT_FAILURE; /* error already reported by handler */
}
finish:
@@ -1022,11 +996,28 @@ prepare_vacuum_command(PGconn *conn, PQExpBuffer sql,
*/
static void
run_vacuum_command(ParallelSlot *free_slot, const char *sql, bool echo,
- const char *table)
+ bool dry_run, const char *table)
{
bool status;
PGconn *conn = free_slot->connection;
+ if (dry_run)
+ {
+ /*
+ * Print the command that we would have run in a real run,
+ * the immediately mark the unused slot as free again.
+ */
+ printf("not executed: %s\n", sql);
+ free_slot->inUse = false;
+ return;
+ }
+
+ /*
+ * Execute the vacuum. All errors are handled in processQueryResult
+ * through ParallelSlotsGetIdle.
+ */
+ ParallelSlotSetHandler(free_slot, TableCommandResultHandler, NULL);
+
if (echo)
printf("%s\n", sql);
--
2.51.1