pgsql: Fix stats collector to recover nicely when system clock goes bac

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix stats collector to recover nicely when system clock goes bac
Date: 2012-06-17 21:12:16
Message-ID: E1SgMlc-0000CD-55@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix stats collector to recover nicely when system clock goes backwards.

Formerly, if the system clock went backwards, the stats collector would
fail to update the stats file any more until the clock reading again
exceeds whatever timestamp was last written into the stats file. Such
glitches in the clock's behavior are not terribly unlikely on machines
not using NTP. Such a scenario has been observed to cause regression test
failures in the buildfarm, and it could have bad effects on the behavior
of autovacuum, so it seems prudent to install some defenses.

We could directly detect the clock going backwards by adding
GetCurrentTimestamp calls in the stats collector's main loop, but that
would hurt performance on platforms where GetCurrentTimestamp is expensive.
To minimize the performance hit in normal cases, adopt a more complicated
scheme wherein backends check for clock skew when reading the stats file,
and if they see it, signal the stats collector by sending an extra stats
inquiry message. The stats collector does an extra GetCurrentTimestamp
only when it receives an inquiry with an apparently out-of-order
timestamp.

To avoid unnecessary GetCurrentTimestamp calls, expand the inquiry messages
to carry the backend's current clock reading as well as its stats cutoff
time. The latter, being intentionally slightly in-the-past, would trigger
more clock rechecks than we need if it were used for this purpose.

We might want to backpatch this change at some point, but let's let it
shake out in the buildfarm for awhile first.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/9e18eacbdff2ae2abd5ff38eee725e6399e39b41

Modified Files
--------------
src/backend/postmaster/pgstat.c | 145 ++++++++++++++++++++++++++++++--------
src/include/pgstat.h | 3 +-
2 files changed, 116 insertions(+), 32 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2012-06-17 23:57:14 pgsql: Make documentation of --help and --version options more consiste
Previous Message Magnus Hagander 2012-06-17 13:24:29 pgsql: Reorder basebackup options, to list pg_basebackup first