postgresql/src/backend/commands
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
..
aggregatecmds.c Make CREATE AGGREGATE complain if the initcond is invalid for the datatype. 2012-10-04 17:54:53 -04:00
alter.c Fix ALTER EXTENSION / SET SCHEMA 2012-10-31 10:52:55 -03:00
analyze.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
async.c Fix NOTIFY to cope with I/O problems, such as out-of-disk-space. 2012-06-29 00:51:34 -04:00
cluster.c Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY. 2012-11-28 21:26:01 -05:00
collationcmds.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
comment.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
constraint.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
conversioncmds.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
copy.c Optimize COPY FREEZE with CREATE TABLE also. 2012-12-07 13:26:52 +00:00
createas.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
dbcommands.c Split out rmgr rm_desc functions into their own files 2012-11-28 13:01:15 -03:00
define.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
discard.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
dropcmds.c Don't trash input list structure in does_not_exist_skipping(). 2012-11-08 11:34:32 -05:00
event_trigger.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
explain.c Improve ruleutils.c's heuristics for dealing with rangetable aliases. 2012-09-21 19:03:10 -04:00
extension.c Fix ALTER EXTENSION / SET SCHEMA 2012-10-31 10:52:55 -03:00
foreigncmds.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
functioncmds.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
indexcmds.c Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY. 2012-11-28 21:26:01 -05:00
lockcmds.c Repair comment mangled by a pgindent run long ago 2012-06-21 15:37:05 -04:00
Makefile Syntax support and documentation for event triggers. 2012-07-18 10:16:16 -04:00
opclasscmds.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
operatorcmds.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
portalcmds.c Revert patch for taking fewer snapshots. 2012-11-26 15:55:43 -05:00
prepare.c Revert patch for taking fewer snapshots. 2012-11-26 15:55:43 -05:00
proclang.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
schemacmds.c Support CREATE SCHEMA IF NOT EXISTS. 2012-10-03 19:47:11 -04:00
seclabel.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
sequence.c Split out rmgr rm_desc functions into their own files 2012-11-28 13:01:15 -03:00
tablecmds.c Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY. 2012-11-28 21:26:01 -05:00
tablespace.c Split out rmgr rm_desc functions into their own files 2012-11-28 13:01:15 -03:00
trigger.c Add missing buffer lock acquisition in GetTupleForTrigger(). 2012-11-30 13:55:55 -05:00
tsearchcmds.c refactor ALTER some-obj SET OWNER implementation 2012-10-03 18:07:46 -03:00
typecmds.c Allow adding values to an enum type created in the current transaction. 2012-12-01 14:27:30 -05:00
user.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
vacuum.c Fix assorted bugs in CREATE/DROP INDEX CONCURRENTLY. 2012-11-28 21:26:01 -05:00
vacuumlazy.c Fix performance problems with autovacuum truncation in busy workloads. 2012-12-11 14:33:08 -06:00
variable.c Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
view.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00