postgresql/src/backend
Kevin Grittner b19e4250b4 Fix performance problems with autovacuum truncation in busy workloads.
In situations where there are over 8MB of empty pages at the end of
a table, the truncation work for trailing empty pages takes longer
than deadlock_timeout, and there is frequent access to the table by
processes other than autovacuum, there was a problem with the
autovacuum worker process being canceled by the deadlock checking
code. The truncation work done by autovacuum up that point was
lost, and the attempt tried again by a later autovacuum worker. The
attempts could continue indefinitely without making progress,
consuming resources and blocking other processes for up to
deadlock_timeout each time.

This patch has the autovacuum worker checking whether it is
blocking any other thread at 20ms intervals. If such a condition
develops, the autovacuum worker will persist the work it has done
so far, release its lock on the table, and sleep in 50ms intervals
for up to 5 seconds, hoping to be able to re-acquire the lock and
try again. If it is unable to get the lock in that time, it moves
on and a worker will try to continue later from the point this one
left off.

While this patch doesn't change the rules about when and what to
truncate, it does cause the truncation to occur sooner, with less
blocking, and with the consumption of fewer resources when there is
contention for the table's lock.

The only user-visible change other than improved performance is
that the table size during truncation may change incrementally
instead of just once.

This problem exists in all supported versions but is infrequently
reported, although some reports of performance problems when
autovacuum runs might be caused by this. Initial commit is just the
master branch, but this should probably be backpatched once the
build farm and general developer usage confirm that there are no
surprising effects.

Jan Wieck
2012-12-11 14:33:08 -06:00
..
access Consistency check should compare last record replayed, not last record read. 2012-12-11 18:54:02 +02:00
bootstrap Add context info to OAT_POST_CREATE security hook 2012-10-23 18:24:24 -03:00
catalog Update minimum recovery point on truncation. 2012-12-10 16:57:16 +02:00
commands Fix performance problems with autovacuum truncation in busy workloads. 2012-12-11 14:33:08 -06:00
executor Support automatically-updatable views. 2012-12-08 18:26:21 -05:00
foreign Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
lib Basic binary heap implementation. 2012-11-29 11:16:59 -05:00
libpq Attempt to un-break Windows builds with USE_LDAP. 2012-12-04 17:25:51 -05:00
main Unify calling conventions for postgres/postmaster sub-main functions 2012-06-25 21:30:12 +03:00
nodes Fix planning of non-strict equivalence clauses above outer joins. 2012-10-18 12:30:10 -04:00
optimizer Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY. 2012-11-28 21:26:01 -05:00
parser COPY FREEZE and mark committed on fresh tables. 2012-12-01 12:54:20 +00:00
po Translation updates 2011-08-17 14:07:46 +03:00
port Change test ExceptionalCondition to return void 2012-11-30 19:24:21 -03:00
postmaster Background worker processes 2012-12-06 17:47:30 -03:00
regex Prevent corner-case core dump in rfree(). 2012-07-15 13:27:54 -04:00
replication Make the streaming replication protocol messages architecture-independent. 2012-11-07 19:09:13 +02:00
rewrite Support automatically-updatable views. 2012-12-08 18:26:21 -05:00
snowball Remove configure flag --disable-shared, as it is no longer used by any 2012-08-30 16:26:53 -04:00
storage Fix performance problems with autovacuum truncation in busy workloads. 2012-12-11 14:33:08 -06:00
tcop Allow adding values to an enum type created in the current transaction. 2012-12-01 14:27:30 -05:00
tsearch Fix logical errors in tsquery selectivity estimation for prefix queries. 2012-09-11 21:23:20 -04:00
utils Support automatically-updatable views. 2012-12-08 18:26:21 -05:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Call check_keywords.pl in maintainer-check 2012-02-27 13:53:12 +02:00
Makefile Fix PGXS support for building loadable modules on AIX. 2012-10-09 21:04:06 -04:00
nls.mk Sort file list when creating gettext-files 2011-12-27 20:20:56 +02:00