Skip to content

Commit 1be0fdb

Browse files
committed
Fix flakey pg_stat_io test
Wrap test of pg_stat_io's tracking of shared buffer reads in a transaction to prevent concurrent accesses (e.g. by autovacuum) causing spurious test failures. Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Author: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://www.postgresql.org/message-id/20230306190919.ai6mxdq3sygyyths%40awork3.anarazel.de
1 parent e20b1ea commit 1be0fdb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/test/regress/expected/stats.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@ SELECT current_setting('fsync') = 'off'
11811181
-- from it to cause it to be read back into shared buffers.
11821182
SELECT sum(reads) AS io_sum_shared_before_reads
11831183
FROM pg_stat_io WHERE io_context = 'normal' AND io_object = 'relation' \gset
1184+
-- Do this in a transaction to prevent spurious failures due to concurrent accesses to our newly
1185+
-- rewritten table, e.g. by autovacuum.
1186+
BEGIN;
11841187
ALTER TABLE test_io_shared SET TABLESPACE regress_tblspace;
11851188
-- SELECT from the table so that the data is read into shared buffers and
11861189
-- io_context 'normal', io_object 'relation' reads are counted.
@@ -1190,6 +1193,7 @@ SELECT COUNT(*) FROM test_io_shared;
11901193
100
11911194
(1 row)
11921195

1196+
COMMIT;
11931197
SELECT pg_stat_force_next_flush();
11941198
pg_stat_force_next_flush
11951199
--------------------------

src/test/regress/sql/stats.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,14 @@ SELECT current_setting('fsync') = 'off'
576576
-- from it to cause it to be read back into shared buffers.
577577
SELECT sum(reads) AS io_sum_shared_before_reads
578578
FROM pg_stat_io WHERE io_context = 'normal' AND io_object = 'relation' \gset
579+
-- Do this in a transaction to prevent spurious failures due to concurrent accesses to our newly
580+
-- rewritten table, e.g. by autovacuum.
581+
BEGIN;
579582
ALTER TABLE test_io_shared SET TABLESPACE regress_tblspace;
580583
-- SELECT from the table so that the data is read into shared buffers and
581584
-- io_context 'normal', io_object 'relation' reads are counted.
582585
SELECT COUNT(*) FROM test_io_shared;
586+
COMMIT;
583587
SELECT pg_stat_force_next_flush();
584588
SELECT sum(reads) AS io_sum_shared_after_reads
585589
FROM pg_stat_io WHERE io_context = 'normal' AND io_object = 'relation' \gset

0 commit comments

Comments
 (0)