1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-29 16:21:20 +03:00

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.
This commit is contained in:
Andrew Dunstan 2024-07-30 06:17:48 -04:00
parent e5ba6a5ab6
commit 787ea8c9d8
3 changed files with 19 additions and 21 deletions

View File

@ -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,

View File

@ -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');
]);

View File

@ -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');
]);