aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2022-09-16 10:07:12 -0700
committerAndres Freund <andres@anarazel.de>2022-09-16 11:28:20 -0700
commit885826f95d1c7803d3ff97bde64078b257543266 (patch)
treebffd899032292212a2f6c4422123f7405fe5a7a2 /src
parentb759bb6714f03e91071b8fe6d29c28a1f87ea4bb (diff)
downloadpostgresql-885826f95d1c7803d3ff97bde64078b257543266.tar.gz
postgresql-885826f95d1c7803d3ff97bde64078b257543266.zip
Fix race condition in stats.sql added in 5264add7847
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 5264add7847 added the test
Diffstat (limited to 'src')
-rw-r--r--src/test/regress/expected/stats.out6
-rw-r--r--src/test/regress/sql/stats.sql1
2 files changed, 7 insertions, 0 deletions
diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out
index 6b233ff4c05..628df302df0 100644
--- a/src/test/regress/expected/stats.out
+++ b/src/test/regress/expected/stats.out
@@ -560,6 +560,12 @@ DROP TABLE prevstats;
-- Test that sessions is incremented when a new session is started in pg_stat_database
SELECT sessions AS db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database()) \gset
\c
+SELECT pg_stat_force_next_flush();
+ pg_stat_force_next_flush
+--------------------------
+
+(1 row)
+
SELECT sessions > :db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database());
?column?
----------
diff --git a/src/test/regress/sql/stats.sql b/src/test/regress/sql/stats.sql
index 096f00ce8be..2f39778b155 100644
--- a/src/test/regress/sql/stats.sql
+++ b/src/test/regress/sql/stats.sql
@@ -294,6 +294,7 @@ DROP TABLE prevstats;
-- Test that sessions is incremented when a new session is started in pg_stat_database
SELECT sessions AS db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database()) \gset
\c
+SELECT pg_stat_force_next_flush();
SELECT sessions > :db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database());
-- Test pg_stat_bgwriter checkpointer-related stats, together with pg_stat_wal