Avoid endless futile table locks in vacuuming.

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Avoid endless futile table locks in vacuuming.
Date: 2015-12-27 15:50:47
Message-ID: CAMkU=1xXv-iFVC3uFrwPja0GOSovYXxFdfryiOdxG-hFG+piMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

If a partially-active table develops a slug of stable all-visible,
non-empty pages at the end of it, then every autovacuum of that table
will skip the end pages on the forward scan, think they might be
truncatable, and take the access exclusive lock to do the truncation.
And then immediately fail when it sees the last page is not empty.
This can persist for an indefinite number of autovac rounds.

This is not generally a problem, as the lock is taken conditionally.
However, the lock is also logged and passed over to any hot standbys,
where it must be replayed unconditionally. This can cause query
cancellations.

The simple solution is to always scan the last page of a table, so it
can be noticed that it is not empty and avoid the truncation attempt.

We could add logic like doing this scan only if wal_level is
hot_standby or higher, or reproducing the REL_TRUNCATE_FRACTION logic
here to scan the last page only if truncation is eminent. But those
seem like needless complications to try to avoid sometimes scanning
one block.

Cheers,

Jeff

Attachment Content-Type Size
always_scan_last_page_v1.patch text/x-patch 1.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2015-12-27 16:05:20 Re: Check for interrupts in bf and xdes crypt()
Previous Message Jeff Janes 2015-12-27 14:53:22 Re: Check for interrupts in bf and xdes crypt()