From: Andrew Dunstan Date: Tue, 30 Jul 2024 10:17:48 +0000 (-0400) Subject: Stabilize xid_wraparound tests X-Git-Tag: REL_18_BETA1~2262 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=800cd3e923597172a29aba49da45753f52996ee8;p=postgresql.git Stabilize xid_wraparound tests The tests had a race condition if autovacuum was set to off. Instead we create all the tables we are interested in with autovacuum disabled, so they are only ever touched when in danger of wraparound. Discussion: https://postgr.es/m/3e2cbd24-f45e-4b2b-ba83-8149214f0a4d@dunslane.net Masahiko Sawada (slightly tweaked by me) Backpatch to release 17 where these tests were introduced. --- diff --git a/src/test/modules/xid_wraparound/t/001_emergency_vacuum.pl b/src/test/modules/xid_wraparound/t/001_emergency_vacuum.pl index 37550b67a4d..2692b35f346 100644 --- a/src/test/modules/xid_wraparound/t/001_emergency_vacuum.pl +++ b/src/test/modules/xid_wraparound/t/001_emergency_vacuum.pl @@ -18,7 +18,6 @@ my $node = PostgreSQL::Test::Cluster->new('main'); $node->init; $node->append_conf( 'postgresql.conf', qq[ -autovacuum = off # run autovacuum only when to anti wraparound autovacuum_naptime = 1s # so it's easier to verify the order of operations autovacuum_max_workers = 1 @@ -27,23 +26,25 @@ log_autovacuum_min_duration = 0 $node->start; $node->safe_psql('postgres', 'CREATE EXTENSION xid_wraparound'); -# Create tables for a few different test scenarios +# Create tables for a few different test scenarios. We disable autovacuum +# on these tables to run it only to prevent wraparound. $node->safe_psql( 'postgres', qq[ -CREATE TABLE large(id serial primary key, data text, filler text default repeat(random()::text, 10)); +CREATE TABLE large(id serial primary key, data text, filler text default repeat(random()::text, 10)) + WITH (autovacuum_enabled = off); INSERT INTO large(data) SELECT generate_series(1,30000); -CREATE TABLE large_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10)); +CREATE TABLE large_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10)) + WITH (autovacuum_enabled = off); INSERT INTO large_trunc(data) SELECT generate_series(1,30000); -CREATE TABLE small(id serial primary key, data text, filler text default repeat(random()::text, 10)); +CREATE TABLE small(id serial primary key, data text, filler text default repeat(random()::text, 10)) + WITH (autovacuum_enabled = off); INSERT INTO small(data) SELECT generate_series(1,15000); -CREATE TABLE small_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10)); +CREATE TABLE small_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10)) + WITH (autovacuum_enabled = off); INSERT INTO small_trunc(data) SELECT generate_series(1,15000); - -CREATE TABLE autovacuum_disabled(id serial primary key, data text) WITH (autovacuum_enabled=false); -INSERT INTO autovacuum_disabled(data) SELECT generate_series(1,1000); ]); # Bump the query timeout to avoid false negatives on slow test systems. @@ -63,7 +64,6 @@ $background_psql->query_safe( DELETE FROM large_trunc WHERE id > 10000; DELETE FROM small WHERE id % 2 = 0; DELETE FROM small_trunc WHERE id > 1000; - DELETE FROM autovacuum_disabled WHERE id % 2 = 0; ]); # Consume 2 billion XIDs, to get us very close to wraparound @@ -107,20 +107,18 @@ $ret = $node->safe_psql( 'postgres', qq[ SELECT relname, age(relfrozenxid) > current_setting('autovacuum_freeze_max_age')::int FROM pg_class -WHERE relname IN ('large', 'large_trunc', 'small', 'small_trunc', 'autovacuum_disabled') +WHERE relname IN ('large', 'large_trunc', 'small', 'small_trunc') ORDER BY 1 ]); -is( $ret, "autovacuum_disabled|f -large|f +is( $ret, "large|f large_trunc|f small|f small_trunc|f", "all tables are vacuumed"); # Check if vacuum failsafe was triggered for each table. my $log_contents = slurp_file($node->logfile, $log_offset); -foreach my $tablename ('large', 'large_trunc', 'small', 'small_trunc', - 'autovacuum_disabled') +foreach my $tablename ('large', 'large_trunc', 'small', 'small_trunc') { like( $log_contents, diff --git a/src/test/modules/xid_wraparound/t/002_limits.pl b/src/test/modules/xid_wraparound/t/002_limits.pl index c02c2871678..aca3fa15149 100644 --- a/src/test/modules/xid_wraparound/t/002_limits.pl +++ b/src/test/modules/xid_wraparound/t/002_limits.pl @@ -27,17 +27,17 @@ my $node = PostgreSQL::Test::Cluster->new('wraparound'); $node->init; $node->append_conf( 'postgresql.conf', qq[ -autovacuum = off # run autovacuum only to prevent wraparound autovacuum_naptime = 1s log_autovacuum_min_duration = 0 ]); $node->start; $node->safe_psql('postgres', 'CREATE EXTENSION xid_wraparound'); -# Create a test table +# Create a test table. We disable autovacuum on the table to run it only +# to prevent wraparound. $node->safe_psql( 'postgres', qq[ -CREATE TABLE wraparoundtest(t text); +CREATE TABLE wraparoundtest(t text) WITH (autovacuum_enabled = off); INSERT INTO wraparoundtest VALUES ('start'); ]); diff --git a/src/test/modules/xid_wraparound/t/003_wraparounds.pl b/src/test/modules/xid_wraparound/t/003_wraparounds.pl index 88063b4b52d..3eaa46a94d0 100644 --- a/src/test/modules/xid_wraparound/t/003_wraparounds.pl +++ b/src/test/modules/xid_wraparound/t/003_wraparounds.pl @@ -21,7 +21,6 @@ my $node = PostgreSQL::Test::Cluster->new('wraparound'); $node->init; $node->append_conf( 'postgresql.conf', qq[ -autovacuum = off # run autovacuum only when to anti wraparound autovacuum_naptime = 1s # so it's easier to verify the order of operations autovacuum_max_workers = 1 @@ -30,10 +29,11 @@ log_autovacuum_min_duration = 0 $node->start; $node->safe_psql('postgres', 'CREATE EXTENSION xid_wraparound'); -# Create a test table +# Create a test table. We disable autovacuum on the table to run +# it only to prevent wraparound. $node->safe_psql( 'postgres', qq[ -CREATE TABLE wraparoundtest(t text); +CREATE TABLE wraparoundtest(t text) WITH (autovacuum_enabled = off); INSERT INTO wraparoundtest VALUES ('beginning'); ]);