Re: Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
Date: 2026-10-24 16:01:07
Message-ID: e88d7d21-7694-4913-bd4c-22266b737076@uni-muenster.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Chao

On 22/10/2026 08:23, Chao Li wrote:
> When ONLY_DATABASE_STATS is enabled, no other option except VERBOSE may be enabled. But the current implementation does not check all options, for example:
> ```
> evantest=# vacuum (ONLY_DATABASE_STATS, SKIP_LOCKED);
> ERROR: ONLY_DATABASE_STATS cannot be specified with other VACUUM options
> evantest=# vacuum (ONLY_DATABASE_STATS, PARALLEL 1);
> VACUUM
> ```

Thanks for the patch!

A few observations:

== error message ==

Instead of creating the new only_database_stats_conflict flag you could
simply add a check in the if (params.options &
VACOPT_ONLY_DATABASE_STATS) block:

@@ -378,15 +378,17 @@ ExecVacuum(ParseState *pstate, VacuumStmt
*vacstmt, bool isTopLevel)
ereport(ERROR,

(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("ONLY_DATABASE_STATS
cannot be specified with a list of tables")));
- /* don't require people to turn off PROCESS_TOAST/MAIN
explicitly */
- if (params.options & ~(VACOPT_VACUUM |
- VACOPT_VERBOSE |
-
VACOPT_PROCESS_MAIN |
-
VACOPT_PROCESS_TOAST |
-
VACOPT_ONLY_DATABASE_STATS))
- ereport(ERROR,
-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("ONLY_DATABASE_STATS
cannot be specified with other VACUUM options")));
+ /* only VERBOSE may be specified alongside
ONLY_DATABASE_STATS */
+ foreach(lc, vacstmt->options)
+ {
+ DefElem *opt = lfirst_node(DefElem, lc);
+
+ if (strcmp(opt->defname, "verbose") != 0 &&
+ strcmp(opt->defname,
"only_database_stats") != 0)
+ ereport(ERROR,
+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+
errmsg("ONLY_DATABASE_STATS cannot be specified with other VACUUM
options")));
+ }

v2 attached implements this handling in ExecVacuum -- feel free to
revert it if you disagree.

== regression tests ==

All error cases are handled in the same path, so theoretically only a
few options (representative ones) would suffice. But I realise that if
the code ever changes, we might end up with untested code. I'd be
inclined to leave them as-is, but I thought I should bring it up. If
it's supposed to cover all possible options, you could consider adding
VACUUM (ONLY_DATABASE_STATS, VERBOSE false).

Thanks!

Best, Jim

Attachment Content-Type Size
v2-0001-Reject-incompatible-options-specified-with-VACUUM.patch text/x-patch 6.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2026-10-24 16:13:04 Re: [PATCH] Refactor pgbench to make future improvements easier
Previous Message Álvaro Herrera 2026-10-24 15:35:33 Re: Do we need an index on pg_constraint.confrelid?