Skip to content

Commit af829cb

Browse files
anarazelpull[bot]
authored andcommitted
Fix race condition in stats.sql added in 5264add
Very occasionally the stats test failed due to the number of sessions not being updated yet. Likely this requires that there is contention on the database's stats entry. Solve this by forcing pending stats to be flushed before fetching the stats. I verified that there are no other test failures after making pgstat_report_stat() only flush stats when force = true. Per message from Tom Lane and buildfarm member crake. Discussion: https://postgr.es/m/3428246.1663271992@sss.pgh.pa.us Backpatch: 15-, where 5264add added the test
1 parent e45acf2 commit af829cb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/test/regress/expected/stats.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ DROP TABLE prevstats;
560560
-- Test that sessions is incremented when a new session is started in pg_stat_database
561561
SELECT sessions AS db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database()) \gset
562562
\c
563+
SELECT pg_stat_force_next_flush();
564+
pg_stat_force_next_flush
565+
--------------------------
566+
567+
(1 row)
568+
563569
SELECT sessions > :db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database());
564570
?column?
565571
----------

src/test/regress/sql/stats.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ DROP TABLE prevstats;
294294
-- Test that sessions is incremented when a new session is started in pg_stat_database
295295
SELECT sessions AS db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database()) \gset
296296
\c
297+
SELECT pg_stat_force_next_flush();
297298
SELECT sessions > :db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database());
298299

299300
-- Test pg_stat_bgwriter checkpointer-related stats, together with pg_stat_wal

0 commit comments

Comments
 (0)