autovacuum: recheck logic - Mailing list pgsql-patches

From Alvaro Herrera
Subject autovacuum: recheck logic
Date
Msg-id 20070327205816.GA5999@alvh.no-ip.org
Whole thread Raw
List pgsql-patches
Hi,

This is the first non-trivial patch to autovacuum multiple workers.

This patch that adds the "recheck" logic to autovacuum worker.  With
this, the worker first builds its table list and then rechecks pgstat
before vacuuming each table to verify that no one has vacuumed the table
in the meantime, before vacuuming it.

In the current autovacuum world this only means that a worker will not
vacuum a table that a user has vacuumed manually.  As discussed, it will
be much more useful as soon as multiple workers are running
concurrently.

To do this, I separated the task of calculating autovacuum parameters
(freeze_min_age, vacuum cost limit and delay, etc) from the autovac
equation calculation (freeze_max_age, pg_class.reltuples, etc).

We now keep track of three lists at the initial pg_class scan:

1. tables that need vacuum or analyze, per equations
2. tables not in (1) that have toast tables
3. toast tables that need vacuum

Then we append those tables in (2) whose toast tables are in (3), to the
(1) list.  The rest are discarded.  So when we need to do the
rechecking, we need to process only those tables that actually needed
vacuuming.  With the previous coding, we would end up rechecking almost
all tables every time (to be exact, all tables that have a toast table).

The autovacuum parameters are only calculated in the second pass (the
rechecking).  The first pass only yields boolean parameters.

Unless there are objections I'll apply this tomorrow.

--
Alvaro Herrera                                http://www.PlanetPostgreSQL.org
"La naturaleza, tan frágil, tan expuesta a la muerte... y tan viva"

Attachment

pgsql-patches by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: [pgsql-patches] O_DIRECT support for Windows
Next
From: "Simon Riggs"
Date:
Subject: Re: [HACKERS] Full page writes improvement, code update