Skip to content

Commit 800cd3e

Browse files
committed
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/[email protected] Masahiko Sawada (slightly tweaked by me) Backpatch to release 17 where these tests were introduced.
1 parent 03b08c8 commit 800cd3e

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/test/modules/xid_wraparound/t/001_emergency_vacuum.pl

+13-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
$node->init;
1919
$node->append_conf(
2020
'postgresql.conf', qq[
21-
autovacuum = off # run autovacuum only when to anti wraparound
2221
autovacuum_naptime = 1s
2322
# so it's easier to verify the order of operations
2423
autovacuum_max_workers = 1
@@ -27,23 +26,25 @@
2726
$node->start;
2827
$node->safe_psql('postgres', 'CREATE EXTENSION xid_wraparound');
2928

30-
# Create tables for a few different test scenarios
29+
# Create tables for a few different test scenarios. We disable autovacuum
30+
# on these tables to run it only to prevent wraparound.
3131
$node->safe_psql(
3232
'postgres', qq[
33-
CREATE TABLE large(id serial primary key, data text, filler text default repeat(random()::text, 10));
33+
CREATE TABLE large(id serial primary key, data text, filler text default repeat(random()::text, 10))
34+
WITH (autovacuum_enabled = off);
3435
INSERT INTO large(data) SELECT generate_series(1,30000);
3536
36-
CREATE TABLE large_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10));
37+
CREATE TABLE large_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10))
38+
WITH (autovacuum_enabled = off);
3739
INSERT INTO large_trunc(data) SELECT generate_series(1,30000);
3840
39-
CREATE TABLE small(id serial primary key, data text, filler text default repeat(random()::text, 10));
41+
CREATE TABLE small(id serial primary key, data text, filler text default repeat(random()::text, 10))
42+
WITH (autovacuum_enabled = off);
4043
INSERT INTO small(data) SELECT generate_series(1,15000);
4144
42-
CREATE TABLE small_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10));
45+
CREATE TABLE small_trunc(id serial primary key, data text, filler text default repeat(random()::text, 10))
46+
WITH (autovacuum_enabled = off);
4347
INSERT INTO small_trunc(data) SELECT generate_series(1,15000);
44-
45-
CREATE TABLE autovacuum_disabled(id serial primary key, data text) WITH (autovacuum_enabled=false);
46-
INSERT INTO autovacuum_disabled(data) SELECT generate_series(1,1000);
4748
]);
4849

4950
# Bump the query timeout to avoid false negatives on slow test systems.
@@ -63,7 +64,6 @@
6364
DELETE FROM large_trunc WHERE id > 10000;
6465
DELETE FROM small WHERE id % 2 = 0;
6566
DELETE FROM small_trunc WHERE id > 1000;
66-
DELETE FROM autovacuum_disabled WHERE id % 2 = 0;
6767
]);
6868

6969
# Consume 2 billion XIDs, to get us very close to wraparound
@@ -107,20 +107,18 @@
107107
'postgres', qq[
108108
SELECT relname, age(relfrozenxid) > current_setting('autovacuum_freeze_max_age')::int
109109
FROM pg_class
110-
WHERE relname IN ('large', 'large_trunc', 'small', 'small_trunc', 'autovacuum_disabled')
110+
WHERE relname IN ('large', 'large_trunc', 'small', 'small_trunc')
111111
ORDER BY 1
112112
]);
113113

114-
is( $ret, "autovacuum_disabled|f
115-
large|f
114+
is( $ret, "large|f
116115
large_trunc|f
117116
small|f
118117
small_trunc|f", "all tables are vacuumed");
119118

120119
# Check if vacuum failsafe was triggered for each table.
121120
my $log_contents = slurp_file($node->logfile, $log_offset);
122-
foreach my $tablename ('large', 'large_trunc', 'small', 'small_trunc',
123-
'autovacuum_disabled')
121+
foreach my $tablename ('large', 'large_trunc', 'small', 'small_trunc')
124122
{
125123
like(
126124
$log_contents,

src/test/modules/xid_wraparound/t/002_limits.pl

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
$node->init;
2828
$node->append_conf(
2929
'postgresql.conf', qq[
30-
autovacuum = off # run autovacuum only to prevent wraparound
3130
autovacuum_naptime = 1s
3231
log_autovacuum_min_duration = 0
3332
]);
3433
$node->start;
3534
$node->safe_psql('postgres', 'CREATE EXTENSION xid_wraparound');
3635

37-
# Create a test table
36+
# Create a test table. We disable autovacuum on the table to run it only
37+
# to prevent wraparound.
3838
$node->safe_psql(
3939
'postgres', qq[
40-
CREATE TABLE wraparoundtest(t text);
40+
CREATE TABLE wraparoundtest(t text) WITH (autovacuum_enabled = off);
4141
INSERT INTO wraparoundtest VALUES ('start');
4242
]);
4343

src/test/modules/xid_wraparound/t/003_wraparounds.pl

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
$node->init;
2222
$node->append_conf(
2323
'postgresql.conf', qq[
24-
autovacuum = off # run autovacuum only when to anti wraparound
2524
autovacuum_naptime = 1s
2625
# so it's easier to verify the order of operations
2726
autovacuum_max_workers = 1
@@ -30,10 +29,11 @@
3029
$node->start;
3130
$node->safe_psql('postgres', 'CREATE EXTENSION xid_wraparound');
3231

33-
# Create a test table
32+
# Create a test table. We disable autovacuum on the table to run
33+
# it only to prevent wraparound.
3434
$node->safe_psql(
3535
'postgres', qq[
36-
CREATE TABLE wraparoundtest(t text);
36+
CREATE TABLE wraparoundtest(t text) WITH (autovacuum_enabled = off);
3737
INSERT INTO wraparoundtest VALUES ('beginning');
3838
]);
3939

0 commit comments

Comments
 (0)