pg_stat_get_snapshot_timestamp() returns the timestamp seen in the "global"
stats file. Because pgstat_write_statsfiles() writes per-DB stats files
before the global file (or at least before renaming it into place), there
is a window where the test backend can see all the stats updates that
wait_for_stats() was checking for (all of which come from the per-DB file)
but also see the same global stats file it had seen at the start of the
test script. This results in a failure in only the "snapshot_newer" query,
as reported by a couple of buildfarm members recently.
I suspect that this ought to be back-patched. Commit
4e37b3e15 has
evidently increased the probability of this window getting hit, but
it's not apparent why it could not have been hit before. I'll refrain
for the moment though.
updated1 bool;
updated2 bool;
updated3 bool;
+ updated4 bool;
begin
-- we don't want to wait forever; loop will exit after 30 seconds
for i in 1 .. 300 loop
SELECT (n_tup_ins > 0) INTO updated3
FROM pg_stat_user_tables WHERE relname='trunc_stats_test4';
- exit when updated1 and updated2 and updated3;
+ -- We must also check explicitly that pg_stat_get_snapshot_timestamp has
+ -- advanced, because that comes from the global stats file which might
+ -- be older than the per-DB stats file we got the other values from.
+ SELECT (pr.snap_ts < pg_stat_get_snapshot_timestamp()) INTO updated4
+ FROM prevstats AS pr;
+
+ exit when updated1 and updated2 and updated3 and updated4;
-- wait a little
perform pg_sleep_for('100 milliseconds');
updated1 bool;
updated2 bool;
updated3 bool;
+ updated4 bool;
begin
-- we don't want to wait forever; loop will exit after 30 seconds
for i in 1 .. 300 loop
SELECT (n_tup_ins > 0) INTO updated3
FROM pg_stat_user_tables WHERE relname='trunc_stats_test4';
- exit when updated1 and updated2 and updated3;
+ -- We must also check explicitly that pg_stat_get_snapshot_timestamp has
+ -- advanced, because that comes from the global stats file which might
+ -- be older than the per-DB stats file we got the other values from.
+ SELECT (pr.snap_ts < pg_stat_get_snapshot_timestamp()) INTO updated4
+ FROM prevstats AS pr;
+
+ exit when updated1 and updated2 and updated3 and updated4;
-- wait a little
perform pg_sleep_for('100 milliseconds');