Fix race condition in stats.sql added in 5264add7847

Andres Freund <andres@anarazel.de>

Commit: 32914d900f90f7f5238a3856e67f6bc5bf05e1d9
Author: Andres Freund <andres@anarazel.de>
Date: 2022-09-16T18:28:20Z
Releases: 16.0
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

Files

PathChange+/−
src/test/regress/expected/stats.out modified +6 −0
src/test/regress/sql/stats.sql modified +1 −0

Discussion

Cited messages not in the archive: 3428246.1663271992@sss.pgh.pa.us