aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2013-09-26 11:24:40 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2013-09-26 11:39:13 +0300
commitca4ac3f6c4fca27d9be1ca880c0a32921017855a (patch)
treece835624ff4e24fcfa9ba4768104a7d6d41ebcf2
parent5d1629919b55816a097d06b6fc5b8448993fa9b0 (diff)
downloadpostgresql-ca4ac3f6c4fca27d9be1ca880c0a32921017855a.tar.gz
postgresql-ca4ac3f6c4fca27d9be1ca880c0a32921017855a.zip
Fix spurious warning after vacuuming a page on a table with no indexes.
There is a rare race condition, when a transaction that inserted a tuple aborts while vacuum is processing the page containing the inserted tuple. Vacuum prunes the page first, which normally removes any dead tuples, but if the inserting transaction aborts right after that, the loop after pruning will see a dead tuple and remove it instead. That's OK, but if the page is on a table with no indexes, and the page becomes completely empty after removing the dead tuple (or tuples) on it, it will be immediately marked as all-visible. That's OK, but the sanity check in vacuum would throw a warning because it thinks that the page contains dead tuples and was nevertheless marked as all-visible, even though it just vacuumed away the dead tuples and so it doesn't actually contain any. Spotted this while reading the code. It's difficult to hit the race condition otherwise, but can be done by putting a breakpoint after the heap_page_prune() call. Backpatch all the way to 8.4, where this code first appeared.
-rw-r--r--src/backend/commands/vacuumlazy.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c
index df89c18f8f2..55889bf9a7c 100644
--- a/src/backend/commands/vacuumlazy.c
+++ b/src/backend/commands/vacuumlazy.c
@@ -761,6 +761,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
{
/* Remove tuples from heap */
lazy_vacuum_page(onerel, blkno, buf, 0, vacrelstats);
+ has_dead_tuples = false;
/*
* Forget the now-vacuumed tuples, and press on, but be careful