Skip to content

Commit fbe9b80

Browse files
Fix autovacuum log output heap truncation issue.
The percentage of blocks from the table value reported by autovacuum log output (following commit 5100010) should never exceed 100% because it describes the state of the table back when lazy_vacuum() was called. The value could nevertheless exceed 100% in the event of heap relation truncation. We failed to compensate for how truncation affects rel_pages. Fix the faulty accounting by using the original rel_pages value instead of the current/final rel_pages value. Reported-By: Andres Freund <[email protected]> Discussion: https://postgr.es/m/[email protected]
1 parent b2d0c7c commit fbe9b80

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backend/access/heap/vacuumlazy.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
777777
(long long) VacuumPageDirty);
778778
if (vacrel->rel_pages > 0)
779779
{
780+
BlockNumber orig_rel_pages;
781+
780782
if (vacrel->do_index_vacuuming)
781783
{
782784
msgfmt = _(" %u pages from table (%.2f%% of total) had %lld dead item identifiers removed\n");
@@ -795,9 +797,10 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
795797
else
796798
appendStringInfo(&buf, _("index scan bypassed by failsafe:"));
797799
}
800+
orig_rel_pages = vacrel->rel_pages + vacrel->pages_removed;
798801
appendStringInfo(&buf, msgfmt,
799802
vacrel->lpdead_item_pages,
800-
100.0 * vacrel->lpdead_item_pages / vacrel->rel_pages,
803+
100.0 * vacrel->lpdead_item_pages / orig_rel_pages,
801804
(long long) vacrel->lpdead_items);
802805
}
803806
for (int i = 0; i < vacrel->nindexes; i++)

0 commit comments

Comments
 (0)