summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera2008-11-03 19:03:41 +0000
committerAlvaro Herrera2008-11-03 19:03:41 +0000
commit52af005e8b029133455addd9a9d5ec85ddbad9c0 (patch)
treecc992b6b8a8952655fc92c795bb7ceef3fb7aa11
parent1a850edf036a1c7dbb9f4fcfeae1e5f2c68cf049 (diff)
Reduce the acceptable staleness of pgstat data for autovacuum, per the
longstanding note in the source that this patch removes.
-rw-r--r--src/backend/postmaster/autovacuum.c6
-rw-r--r--src/backend/postmaster/pgstat.c13
2 files changed, 14 insertions, 5 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 5d1b80a86f..fee9d98158 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -2149,8 +2149,10 @@ do_autovacuum(void)
* It could have changed if something else processed the table while
* we weren't looking.
*
- * FIXME we ignore the possibility that the table was finished being
- * vacuumed in the last 500ms (PGSTAT_STAT_INTERVAL). This is a bug.
+ * Note: we have a special case in pgstat code to ensure that the stats
+ * we read are as up-to-date as possible, to avoid the problem that
+ * somebody just finished vacuuming this table. The window to the race
+ * condition is not closed but it is very small.
*/
MemoryContextSwitchTo(AutovacMemCxt);
tab = table_recheck_autovac(relid, table_toast_map);
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index c3a767bd91..916a4c2e7d 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -3381,7 +3381,10 @@ backend_read_statsfile(void)
/*
* We set the minimum acceptable timestamp to PGSTAT_STAT_INTERVAL msec
* before now. This indirectly ensures that the collector needn't write
- * the file more often than PGSTAT_STAT_INTERVAL.
+ * the file more often than PGSTAT_STAT_INTERVAL. In an autovacuum
+ * worker, however, we want a lower delay to avoid using stale data, so we
+ * use PGSTAT_RETRY_DELAY (since the number of worker is low, this
+ * shouldn't be a problem).
*
* Note that we don't recompute min_ts after sleeping; so we might end up
* accepting a file a bit older than PGSTAT_STAT_INTERVAL. In practice
@@ -3389,8 +3392,12 @@ backend_read_statsfile(void)
* PGSTAT_STAT_INTERVAL; and we don't want to lie to the collector about
* what our cutoff time really is.
*/
- min_ts = TimestampTzPlusMilliseconds(GetCurrentTimestamp(),
- -PGSTAT_STAT_INTERVAL);
+ if (IsAutoVacuumWorkerProcess())
+ min_ts = TimestampTzPlusMilliseconds(GetCurrentTimestamp(),
+ -PGSTAT_RETRY_DELAY);
+ else
+ min_ts = TimestampTzPlusMilliseconds(GetCurrentTimestamp(),
+ -PGSTAT_STAT_INTERVAL);
/*
* Loop until fresh enough stats file is available or we ran out of time.