diff options
author | Fujii Masao <fujii@postgresql.org> | 2025-09-25 01:38:54 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2025-09-25 01:38:54 +0900 |
commit | 879c492480d0e9ad8155c4269f95c5e8add41901 (patch) | |
tree | e46ba9c67aba6d0c895aaa635793dbfd89bedb19 | |
parent | ae8ea7278c16a23aa7dfb56c531706c18628ba55 (diff) |
vacuumdb: Do not run VACUUM (ONLY_DATABASE_STATS) when --analyze-only.HEADorigin/masterorigin/HEADmaster
Previously, vacuumdb --analyze-only issued VACUUM (ONLY_DATABASE_STATS)
at the end. Since --analyze-only is meant to update optimizer statistics only,
this extra VACUUM command is unnecessary.
This commit prevents vacuumdb --analyze-only from running that redundant
VACUUM command.
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Mircea Cadariu <cadariu.mircea@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEqHGa-k=wbRMucUVihHVXk4NQkK94GNN=ym9cQ5HBSHg@mail.gmail.com
-rw-r--r-- | src/bin/scripts/t/100_vacuumdb.pl | 6 | ||||
-rw-r--r-- | src/bin/scripts/vacuumdb.c | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl index 945c30df156..a16fad593f7 100644 --- a/src/bin/scripts/t/100_vacuumdb.pl +++ b/src/bin/scripts/t/100_vacuumdb.pl @@ -351,5 +351,11 @@ $node->issues_sql_like( ], qr/statement: ANALYZE public.parent_table/s, '--analyze-only updates statistics for partitioned tables'); +$node->issues_sql_unlike( + [ + 'vacuumdb', '--analyze-only', 'postgres' + ], + qr/statement:\ VACUUM/sx, + '--analyze-only does not run vacuum'); done_testing(); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index fd236087e90..6e30f223efe 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -750,7 +750,8 @@ vacuum_one_database(ConnParams *cparams, } /* If we used SKIP_DATABASE_STATS, mop up with ONLY_DATABASE_STATS */ - if (vacopts->skip_database_stats && stage == ANALYZE_NO_STAGE) + if (vacopts->skip_database_stats && stage == ANALYZE_NO_STAGE && + !vacopts->analyze_only) { const char *cmd = "VACUUM (ONLY_DATABASE_STATS);"; ParallelSlot *free_slot = ParallelSlotsGetIdle(sa, NULL); |