Avoid endless futile table locks in vacuuming. - Mailing list pgsql-hackers

From Jeff Janes
Subject Avoid endless futile table locks in vacuuming.
Date
Msg-id CAMkU=1xXv-iFVC3uFrwPja0GOSovYXxFdfryiOdxG-hFG+piMQ@mail.gmail.com
Whole thread Raw
Responses Re: Avoid endless futile table locks in vacuuming.  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-hackers by date:

Previous
From: Jeff Janes
Date:
Subject: Re: Check for interrupts in bf and xdes crypt()
Next
From: Alvaro Herrera
Date:
Subject: Re: Check for interrupts in bf and xdes crypt()