From bb32940d12df1cadcd94bb7b4a071044c837cc9b Mon Sep 17 00:00:00 2001 From: Shihao Zhong Date: Wed, 16 Sep 2026 21:56:17 -0400 Subject: [PATCH v7 4/4] Add a TAP test for per-index vacuum progress reporting Use the injection point added by the previous commit to stop with a known index in progress, and check that pg_stat_progress_vacuum names that index and then moves on to the next one rather than carrying a stale value over. --- src/test/modules/test_misc/meson.build | 1 + .../test_misc/t/016_vacuum_progress.pl | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/test/modules/test_misc/t/016_vacuum_progress.pl diff --git a/src/test/modules/test_misc/meson.build b/src/test/modules/test_misc/meson.build index 5d81f5b13be..27b33a2c61e 100644 --- a/src/test/modules/test_misc/meson.build +++ b/src/test/modules/test_misc/meson.build @@ -24,6 +24,7 @@ tests += { 't/013_temp_obj_multisession.pl', 't/014_log_statement_max_length.pl', 't/015_temp_schema_exit_deferrable.pl', + 't/016_vacuum_progress.pl', ], # The injection points are cluster-wide, so disable installcheck 'runningcheck': false, diff --git a/src/test/modules/test_misc/t/016_vacuum_progress.pl b/src/test/modules/test_misc/t/016_vacuum_progress.pl new file mode 100644 index 00000000000..525e7621afd --- /dev/null +++ b/src/test/modules/test_misc/t/016_vacuum_progress.pl @@ -0,0 +1,69 @@ +# Copyright (c) 2026, PostgreSQL Global Development Group +# +# Check that pg_stat_progress_vacuum reports the index being vacuumed. + +use strict; +use warnings FATAL => 'all'; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +if (($ENV{enable_injection_points} // 'no') ne 'yes') +{ + plan skip_all => 'Injection points not supported by this build'; +} + +my $node = PostgreSQL::Test::Cluster->new('vacprog'); +$node->init; +$node->append_conf('postgresql.conf', 'autovacuum = off'); +$node->start; + +if (!$node->check_extension('injection_points')) +{ + plan skip_all => 'Extension injection_points not installed'; +} + +$node->safe_psql( + 'postgres', qq{ + CREATE EXTENSION injection_points; + CREATE TABLE vacprog (a int, b int); + INSERT INTO vacprog SELECT g, g FROM generate_series(1, 20000) g; + CREATE INDEX vacprog_a ON vacprog (a); + CREATE INDEX vacprog_b ON vacprog (b); + DELETE FROM vacprog WHERE a % 2 = 0; + SELECT injection_points_attach('vacuum-index-in-progress', 'wait'); +}); + +# Stop inside the per index loop, with one index known to be in progress. +my $vac = $node->background_psql('postgres'); +$vac->query_until(qr//, "VACUUM vacprog;\n"); +$node->wait_for_event('client backend', 'vacuum-index-in-progress'); + +my $first = $node->safe_psql( + 'postgres', q{ + SELECT c.relname FROM pg_stat_progress_vacuum v + JOIN pg_class c ON c.oid = v.current_index_relid + WHERE v.relid = 'vacprog'::regclass}); +like($first, qr/^vacprog_[ab]$/, "reports the index being vacuumed, $first"); + +$node->safe_psql('postgres', + "SELECT injection_points_wakeup('vacuum-index-in-progress');"); + +# The other index must be reported in its turn. A value left over from the +# first index would never satisfy this. +ok( $node->poll_query_until( + 'postgres', qq{ + SELECT count(*) = 1 FROM pg_stat_progress_vacuum v + JOIN pg_class c ON c.oid = v.current_index_relid + WHERE v.relid = 'vacprog'::regclass AND c.relname <> '$first'}), + 'reports the next index in turn'); + +$node->safe_psql( + 'postgres', q{ + SELECT injection_points_detach('vacuum-index-in-progress'); + SELECT injection_points_wakeup('vacuum-index-in-progress'); +}); +$vac->quit; +$node->stop; + +done_testing(); -- 2.37.1 (Apple Git-137.1)