Cancelling Blocking Autovacuums

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Cancelling Blocking Autovacuums
Date: 2007-10-11 19:07:07
Message-ID: 1192129627.4233.426.camel@ebony.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

After much thought and discussion, here is my proposal of how to handle
autovacuum workers which block out user-initiated SQL statements.

Autovacuum workers running VACUUM, VACUUM ANALYZE and ANALYZE can give
problems by blocking out other users in various circumstances. There are
good cases for all 3 statements to be cancelled, so we don't bother to
enquire what exactly the AV worker is actually doing before we cancel
it. If an AV worker task is cancelled it will be scheduled to run again
on the next cycle. It is possible, though unlikely that this will result
in indefinite starvation; in that case existing log message will warn
the user.

We check for blocking AV workers when we enter the deadlock detector. At
this stage we must allow the deadlock detector to proceed to its
conclusion in case any hard or soft deadlocks exist. It is possible that
our lock queue waits on an AV worker *and* we are part of a deadlock
with a third process, so we must just let the detector roll.

If we find no deadlock, yet the head of the wait queue is an AV worker,
then we send a cancel (SIGINT) to that process. It's possible for
multiple backends to do this, though that shouldn't be a problem.

If an AV worker is not a current lock holder we wait normally, since it
is presumed the user knows about other conflicting lock holders and
would have to have waited anyway. In that case the AV worker is not
cancelled. That aspect is changeable with some thought.

A patch that implements this is being sent to -patches now.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2007-10-11 19:21:25 Re: Timezone database changes
Previous Message Andrew Dunstan 2007-10-11 18:59:13 Re: full text search in 8.3