Skip site navigation (1) Skip section navigation (2)

pgsql: Fix stats collector to recover nicely when system clock goesbac

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 goesbac
Date: 2012-06-17 21:12:16
Message-ID: (view raw, whole thread or download thread mbox)
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

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.



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

pgsql-committers by date

Next:From: Peter EisentrautDate: 2012-06-17 23:57:14
Subject: pgsql: Make documentation of --help and --version options moreconsiste
Previous:From: Magnus HaganderDate: 2012-06-17 13:24:29
Subject: pgsql: Add missing subtitle for compressed archive logs

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group