test_exclude_database_results.txt

text/plain

Filename: test_exclude_database_results.txt
Type: text/plain
Part: 0
Message: [PATCH] vacuumdb: Add --exclude-database option
============================================================
VACUUMDB --exclude-database FEATURE TEST SUITE
============================================================
Date: Thu May 14 22:48:56 PDT 2026
PostgreSQL: PostgreSQL 19devel on aarch64-darwin, compiled by clang-21.0.0, 64-bit
vacuumdb: vacuumdb (PostgreSQL) 19devel

Available databases:
 postgres
 template1
 test_db1
 test_db2
 test_db3



================================================================
TEST 1: Single database exclusion
================================================================
Description: Exclude test_db1 from vacuum --all. Expected: exit 0, test_db1 skipped, other dbs vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all --exclude-database=test_db1
Expected: pass
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db2"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS
  ✅ 'vacuuming database "test_db1"' correctly absent from output
  ✅ All other databases vacuumed (4/4)

================================================================
TEST 2: Multiple database exclusions (-D db1 -D db2)
================================================================
Description: Exclude test_db1 and test_db2. Expected: exit 0, both excluded, test_db3 still vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all -D test_db1 -D test_db2
Expected: pass
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS
  ✅ 'vacuuming database "test_db1"' correctly absent from output
  ✅ 'vacuuming database "test_db2"' correctly absent from output
  ✅ 'vacuuming database "test_db3"' found in output

================================================================
TEST 3: Exclude ALL databases (edge case)
================================================================
Description: Exclude every connectable database. Expected: exit 0, no vacuum ops, graceful no-op.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all  -D postgres -D test_db1 -D template1 -D test_db2 -D test_db3
Expected: pass
---
Exit Code: 0
Output:

---
RESULT: ✅ PASS

================================================================
TEST 4: Exclude non-existent database
================================================================
Description: Exclude a name that doesn't exist. Expected: exit 0, silently ignored, all real dbs vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all --exclude-database=this_db_does_not_exist_xyz
Expected: pass
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db1"
vacuumdb: vacuuming database "test_db2"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS
  ✅ 'vacuuming database "postgres"' found in output

================================================================
TEST 5: Exclude maintenance database (postgres)
================================================================
Description: Exclude postgres (used for listing). Expected: exit 0, postgres skipped, others vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all --exclude-database=postgres
Expected: pass
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db1"
vacuumdb: vacuuming database "test_db2"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS
  ✅ 'vacuuming database "postgres"' correctly absent from output
  ✅ All other databases vacuumed (4/4)

================================================================
TEST 6: Case sensitivity - exact case excludes MixedCaseDB
================================================================
Description: TEST 6.1: Exclude MixedCaseDB with exact case. Expected: exit 0, MixedCaseDB NOT vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all --exclude-database=MixedCaseDB
Expected: pass
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db1"
vacuumdb: vacuuming database "test_db2"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS
  ✅ 'vacuuming database "MixedCaseDB"' correctly absent from output

----------------------------------------------------------------
TEST 6.2: Case sensitivity - wrong case does NOT exclude
----------------------------------------------------------------
Description: Exclude with wrong case 'mixedcasedb'. Expected: MixedCaseDB IS vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all --exclude-database=mixedcasedb
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "MixedCaseDB"
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db1"
vacuumdb: vacuuming database "test_db2"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS (MixedCaseDB was vacuumed — wrong case did not exclude it)

================================================================
TEST 7: --exclude-database without --all (must fail)
================================================================
Description: Use -D without --all. Expected: non-zero exit, error: cannot use --exclude-database without --all.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb -D test_db1
Expected: fail
---
Exit Code: 1
Output:
vacuumdb: error: cannot use --exclude-database without --all option
---
RESULT: ✅ PASS (correctly failed)
  ✅ Correct error message: 'cannot use --exclude-database without --all'

================================================================
TEST 8: --exclude-database with -d (must fail)
================================================================
Description: Use -D with -d. Expected: non-zero exit, -D requires --all but -d conflicts with --all.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb -d postgres -D test_db1
Expected: fail
---
Exit Code: 1
Output:
vacuumdb: error: cannot use --exclude-database without --all option
---
RESULT: ✅ PASS (correctly failed)

================================================================
TEST 9: SQL injection attempt in database name
================================================================
Description: Inject SQL via -D value. Expected: exit 0, safely escaped, no injection, all dbs vacuumed.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb --all --exclude-database="'; DROP TABLE pg_class; --"
Expected: pass
---
Exit Code: 0
Output:
vacuumdb: vacuuming database "MixedCaseDB"
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
vacuumdb: vacuuming database "test_db1"
vacuumdb: vacuuming database "test_db2"
vacuumdb: vacuuming database "test_db3"
---
RESULT: ✅ PASS

================================================================
TEST 10: --help shows --exclude-database
================================================================
Description: Run vacuumdb --help and check output.
Expected: Output contains '-D, --exclude-database=DBNAME'
---
Output:
vacuumdb cleans and analyzes a PostgreSQL database.

Usage:
  vacuumdb [OPTION]... [DBNAME]

Options:
  -a, --all                       vacuum all databases
      --buffer-usage-limit=SIZE   size of ring buffer used for vacuum
  -d, --dbname=DBNAME             database to vacuum
  -D, --exclude-database=DBNAME   exclude database from --all operation
      --disable-page-skipping     disable all page-skipping behavior
      --dry-run                   show the commands that would be sent to the server
  -e, --echo                      show the commands being sent to the server
  -f, --full                      do full vacuuming
  -F, --freeze                    freeze row transaction information
      --force-index-cleanup       always remove index entries that point to dead tuples
  -j, --jobs=NUM                  use this many concurrent connections to vacuum
      --min-mxid-age=MXID_AGE     minimum multixact ID age of tables to vacuum
      --min-xid-age=XID_AGE       minimum transaction ID age of tables to vacuum
      --missing-stats-only        only analyze relations with missing statistics
      --no-index-cleanup          don't remove index entries that point to dead tuples
      --no-process-main           skip the main relation
      --no-process-toast          skip the TOAST table associated with the table to vacuum
      --no-truncate               don't truncate empty pages at the end of the table
  -n, --schema=SCHEMA             vacuum tables in the specified schema(s) only
  -N, --exclude-schema=SCHEMA     do not vacuum tables in the specified schema(s)
  -P, --parallel=PARALLEL_WORKERS use this many background workers for vacuum, if available
  -q, --quiet                     don't write any messages
      --skip-locked               skip relations that cannot be immediately locked
  -t, --table='TABLE[(COLUMNS)]'  vacuum specific table(s) only
  -v, --verbose                   write a lot of output
  -V, --version                   output version information, then exit
  -z, --analyze                   update optimizer statistics
  -Z, --analyze-only              only update optimizer statistics; no vacuum
      --analyze-in-stages         only update optimizer statistics, in multiple
                                  stages for faster results; no vacuum
  -?, --help                      show this help, then exit

Connection options:
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name to connect as
  -w, --no-password         never prompt for password
  -W, --password            force password prompt
  --maintenance-db=DBNAME   alternate maintenance database

Read the description of the SQL command VACUUM for details.

Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>
---
RESULT: ✅ PASS

================================================================
TEST 11: -d with -D and --all (must fail)
================================================================
Description: Use -d postgres -D test_db1 --all. Expected: non-zero exit, -d and --all conflict.
Command: /Users/mmohali/Kiro_projects/vacuumdb/pghome/bin/vacuumdb -d postgres -D test_db1 --all
Expected: fail
---
Exit Code: 1
Output:
vacuumdb: error: cannot vacuum all databases and a specific one at the same time
---
RESULT: ✅ PASS (correctly failed)

============================================================
TEST SUMMARY
============================================================
Total checks: 22
Passed:       22
Failed:       0

ALL TESTS PASSED

Results saved to: ./test_exclude_database_results.txt