Re: [PATCH] vacuumdb: Add --exclude-database option

Поиск
Список
Период
Сортировка
Искать

Re: [PATCH] vacuumdb: Add --exclude-database option

От:
Quan Zongliang <quanzongliang@yeah.net>
Дата:


On 5/16/26 12:47 AM, Mohamed ALi wrote:
> Hi hackers,
> 
> Attached is a patch that adds --exclude-database (-D) to vacuumdb,
> allowing users to skip specific databases when using --all.
> 
> Motivation
> ----------
> 
> "vacuumdb --all" vacuums every connectable database without exception.
> In production environments, operators often need to skip certain databases
> during maintenance — for example, test databases, large inactive databases
> with historical data.
> The current workaround is to manually vacuum each database
> individually or write wrapper scripts.
> 
The parameter "D and d(dname)" conforms to the usage of "N and n." 
Adhering to the original definition, this is fine.

In the vacuum_all_databases function. If the condition 'if 
(dbsToExclude)' is used. All 'exclude-database' processing (including 
variable definitions) can be placed in a separate code block. How about 
this? Irrelevant personal preferences.

--
Quan Zongliang

> Usage
> -----
> 
>      vacuumdb --all --exclude-database=test_db
>      vacuumdb --all -D db1 -D db2 -D db3
> 
> The option requires --all
> 
> Testing
> -------
> 
> The patch passes all existing vacuumdb TAP tests (100_vacuumdb,
> 101_vacuumdb_all, 102_vacuumdb_stages) and includes 4 new TAP tests
> in 101_vacuumdb_all.pl covering exclusion, multiple exclusions, and
> error cases.
> 
> I've also attached a standalone test script (test_exclude_database.sh)
> that exercises the feature with 11 test scenarios:
> 
>    1. Single database exclusion
>    2. Multiple database exclusions (-D db1 -D db2)
>    3. Exclude all databases
>    4. Exclude non-existent database (silently ignored)
>    5. Exclude maintenance database (postgres)
>    6. Case sensitivity (exact case excludes, wrong case does not)
>    7. --exclude-database without --all (error)
>    8. --exclude-database with -d (error)
>    9. SQL injection protection
>   10. --help output
>   11. -d with -D and --all (conflicting options error)
> 
> All tests pass. The test script is portable — it uses standard libpq
> environment variables and auto-detects binaries. Test output is also
> attached (test_exclude_database_results.txt).
> 



Re: [PATCH] vacuumdb: Add --exclude-database option

От:
wenhui qiu <qiuwenhuifx@gmail.com>
Дата:
HI 

> In the vacuum_all_databases function. If the condition 'if
> (dbsToExclude)' is used. All 'exclude-database' processing (including
> variable definitions) can be placed in a separate code block. How about
> this? Irrelevant personal preferences.
   Agree +1




Thanks   

Re: [PATCH] vacuumdb: Add --exclude-database option

От:
Mohamed ALi <moali.pg@gmail.com>
Дата:
Вложения:
Hi Quan, wenhui,

Thanks for the review and feedback.

On Thu, Jun 5, 2026 at 09:25:52 AM, Quan Zongliang wrote:
> In the vacuum_all_databases function. If the condition 'if
> (dbsToExclude)' is used. All 'exclude-database' processing (including
> variable definitions) can be placed in a separate code block.

Good suggestion. Attached is v2 incorporating this change, the
exclude-database logic (including the `cell` and `first` variable
declarations) is now scoped inside an `if (dbsToExclude)` block.
This keeps the variables out of the function's top-level scope when
the feature isn't being used.


The patch is also tracked in CommitFest PG20-1:
https://commitfest.postgresql.org/patch/6833/

-- 
Mohamed Ali
AWS RDS
FAQ