Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
Hi,
The VACUUM option ONLY_DATABASE_STATS can only be used with VERBOSE. Other options should be rejected, as the documentation describes:
```
ONLY_DATABASE_STATS
Specifies that VACUUM should do nothing except
update the database-wide statistics about oldest unfrozen XIDs.
When this option is specified,
the table_and_columns
list must be empty, and no other option may be enabled
except VERBOSE.
```
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
```
With SKIP_LOCKED, the command fails as expected, while with PARALLEL 1 the command succeeds, which doesn't follow the doc and may confuse users.
In the fix, I considered whether rejection should be based on presence or value. VACUUM itself uses both approaches. When FULL rejects BUFFER_USAGE_LIMIT, the check is presence based:
```
evantest=# vacuum (FULL, BUFFER_USAGE_LIMIT 0);
ERROR: BUFFER_USAGE_LIMIT cannot be specified for VACUUM FULL
```
When FULL rejects PARALLEL, the check is value based:
```
evantest=# vacuum (FULL, PARALLEL 0);
VACUUM
evantest=# vacuum (FULL, PARALLEL 1);
ERROR: VACUUM FULL cannot be performed in parallel
```
I chose the presence based approach because in the PARALLEL case, the error specifically states that VACUUM FULL cannot be performed in parallel. In contrast, the ONLY_DATABASE_STATS error generically states that it cannot be specified with other VACUUM options, which is closer to when FULL rejects BUFFER_USAGE_LIMIT. Accordingly, I also updated the doc by replacing “enabled” with “specified".
See attached patch for the fix details.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Re: Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
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
Re: Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
> On Oct 25, 2026, at 00:01, Jim Jones wrote:
>
> 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!
Hi Jim,
Thank you very much for the review.
>
> 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")));
> + }
>
I think your suggestion expresses “only these two option names are allowed” in one place, which is good. However, I am also concerned that if a future option needs a similar check, following this pattern would require another loop.
When I wrote the code, I followed the “_given” pattern used in many places, such as publicationcmds.c and foreigncmds.c, which records whether an option is specified during parsing.
So, I’d leave the v1 implementation as it is and wait for more opinions.
> 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).
Added the test case in v3.
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Re: Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
От:
Jim Jones <jim.jones@uni-muenster.de>
Дата:
On 26/10/2026 01:20, Chao Li wrote: > I think your suggestion expresses “only these two option names are allowed” in one place, which is good. However, I am also concerned that if a future option needs a similar check, following this pattern would require another loop. > > When I wrote the code, I followed the “_given” pattern used in many places, such as publicationcmds.c and foreigncmds.c, which records whether an option is specified during parsing. > > So, I’d leave the v1 implementation as it is and wait for more opinions. Although I think that a future option would need the same care in both approaches, I agree that following a known pattern is preferable. +1 >> 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). > Added the test case in v3. Thanks! Best, Jim
Re: Reject incompatible options specified with VACUUM ONLY_DATABASE_STATS
От:
Ishjaap Singh <ishjaap.singh07@gmail.com>
Дата:
On Mon, Oct 26, 2026, Chao Li wrote: > So, I'd leave the v1 implementation as it is and wait for more > opinions. Hi Chao, I tested v3 on master (207b5293b8d) against an unpatched build. make check and 100_vacuumdb.pl pass. PARALLEL, INDEX_CLEANUP, TRUNCATE and BUFFER_USAGE_LIMIT are now rejected with ONLY_DATABASE_STATS. Rejecting options given as off (PARALLEL 0, PROCESS_TOAST false, ...) seems fine to me for master; it matches how FULL handles BUFFER_USAGE_LIMIT. vacuumdb only sends a bare VACUUM (ONLY_DATABASE_STATS), and it still works with all the flags I tried. Optionally, a test for VACUUM (ONLY_DATABASE_STATS, PARALLEL 0) would cover the presence-over-value choice. Looks good to me. Thanks, Ishjaap Singh