Commit 17eaae98 authored by Andres Freund's avatar Andres Freund

Fix logging of pages skipped due to pins during vacuum.

The new logging introduced in 35192f06 made the incorrect assumption
that scan_all vacuums would always wait for buffer pins; but they only
do so if the page actually needs to be frozen.

Fix that inaccuracy by removing the difference in log output based on
scan_all and just always remove the same message.  I chose to keep the
split log message from the original commit for now, it seems likely
that it'll be of use in the future.

Also merge the line about buffer pins in autovacuum's log output into
the existing "pages: ..." line. It seems odd to have a separate line
about pins, without the "topic: " prefix others have.

Also rename the new 'pinned_pages' variable to 'pinskipped_pages'
because it actually tracks the number of pages that could *not* be
pinned.

Discussion: 20150104005324.GC9626@awork2.anarazel.de
parent 2048e5b8
...@@ -105,7 +105,7 @@ typedef struct LVRelStats ...@@ -105,7 +105,7 @@ typedef struct LVRelStats
BlockNumber old_rel_pages; /* previous value of pg_class.relpages */ BlockNumber old_rel_pages; /* previous value of pg_class.relpages */
BlockNumber rel_pages; /* total number of pages */ BlockNumber rel_pages; /* total number of pages */
BlockNumber scanned_pages; /* number of pages we examined */ BlockNumber scanned_pages; /* number of pages we examined */
BlockNumber pinned_pages; /* # of pages we could not initially lock */ BlockNumber pinskipped_pages; /* # of pages we skipped due to a pin */
double scanned_tuples; /* counts only tuples on scanned pages */ double scanned_tuples; /* counts only tuples on scanned pages */
double old_rel_tuples; /* previous value of pg_class.reltuples */ double old_rel_tuples; /* previous value of pg_class.reltuples */
double new_rel_tuples; /* new estimated total # of tuples */ double new_rel_tuples; /* new estimated total # of tuples */
...@@ -356,19 +356,10 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, ...@@ -356,19 +356,10 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
get_namespace_name(RelationGetNamespace(onerel)), get_namespace_name(RelationGetNamespace(onerel)),
RelationGetRelationName(onerel), RelationGetRelationName(onerel),
vacrelstats->num_index_scans); vacrelstats->num_index_scans);
appendStringInfo(&buf, _("pages: %u removed, %u remain\n"), appendStringInfo(&buf, _("pages: %u removed, %u remain, %u skipped due to pins\n"),
vacrelstats->pages_removed, vacrelstats->pages_removed,
vacrelstats->rel_pages); vacrelstats->rel_pages,
if (vacrelstats->pinned_pages > 0) vacrelstats->pinskipped_pages);
{
if (scan_all)
appendStringInfo(&buf, _("waited for %u buffer pins\n"),
vacrelstats->pinned_pages);
else
appendStringInfo(&buf,
_("skipped %u pages due to buffer pins\n"),
vacrelstats->pinned_pages);
}
appendStringInfo(&buf, appendStringInfo(&buf,
_("tuples: %.0f removed, %.0f remain, %.0f are dead but not yet removable\n"), _("tuples: %.0f removed, %.0f remain, %.0f are dead but not yet removable\n"),
vacrelstats->tuples_deleted, vacrelstats->tuples_deleted,
...@@ -634,8 +625,6 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -634,8 +625,6 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
/* We need buffer cleanup lock so that we can prune HOT chains. */ /* We need buffer cleanup lock so that we can prune HOT chains. */
if (!ConditionalLockBufferForCleanup(buf)) if (!ConditionalLockBufferForCleanup(buf))
{ {
vacrelstats->pinned_pages++;
/* /*
* If we're not scanning the whole relation to guard against XID * If we're not scanning the whole relation to guard against XID
* wraparound, it's OK to skip vacuuming a page. The next vacuum * wraparound, it's OK to skip vacuuming a page. The next vacuum
...@@ -644,6 +633,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -644,6 +633,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
if (!scan_all) if (!scan_all)
{ {
ReleaseBuffer(buf); ReleaseBuffer(buf);
vacrelstats->pinskipped_pages++;
continue; continue;
} }
...@@ -663,6 +653,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -663,6 +653,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
{ {
UnlockReleaseBuffer(buf); UnlockReleaseBuffer(buf);
vacrelstats->scanned_pages++; vacrelstats->scanned_pages++;
vacrelstats->pinskipped_pages++;
continue; continue;
} }
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
...@@ -1129,15 +1120,8 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -1129,15 +1120,8 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
nkeep); nkeep);
appendStringInfo(&buf, _("There were %.0f unused item pointers.\n"), appendStringInfo(&buf, _("There were %.0f unused item pointers.\n"),
nunused); nunused);
if (vacrelstats->pinned_pages > 0) appendStringInfo(&buf, _("Skipped %u pages due to buffer pins.\n"),
{ vacrelstats->pinskipped_pages);
if (scan_all)
appendStringInfo(&buf, _("Waited for %u buffer pins.\n"),
vacrelstats->pinned_pages);
else
appendStringInfo(&buf, _("Skipped %u pages due to buffer pins.\n"),
vacrelstats->pinned_pages);
}
appendStringInfo(&buf, _("%u pages are entirely empty.\n"), appendStringInfo(&buf, _("%u pages are entirely empty.\n"),
empty_pages); empty_pages);
appendStringInfo(&buf, _("%s."), appendStringInfo(&buf, _("%s."),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment