From 5bdc203b9eeda5e43546e0b77dd83d06894fb76b Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 6 Dec 2017 17:02:17 -0300 Subject: [PATCH 2/2] blkno/rel context info for lazy_scan_heap --- src/backend/commands/vacuumlazy.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index f95346acdb..332adc6550 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -131,6 +131,14 @@ typedef struct LVRelStats bool lock_waiter_detected; } LVRelStats; +/* + * Struct to hold context info for lazy_scan_heap. + */ +typedef struct LazyScanHeapInfo +{ + Relation relation; + BlockNumber blkno; +} LazyScanHeapInfo; /* A few variables that don't seem worth passing around as parameters */ static int elevel = -1; @@ -146,6 +154,7 @@ static BufferAccessStrategy vac_strategy; static void lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, Relation *Irel, int nindexes, bool aggressive); +static void lazy_scan_heap_cb(void *arg); static void lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats); static bool lazy_check_needs_freeze(Buffer buf, bool *hastup); static void lazy_vacuum_index(Relation indrel, @@ -476,6 +485,8 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, nkeep, nunused; IndexBulkDeleteResult **indstats; + ErrorContextCallback callback; + LazyScanHeapInfo info; int i; PGRUsage ru0; Buffer vmbuffer = InvalidBuffer; @@ -526,6 +537,15 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, initprog_val[2] = vacrelstats->max_dead_tuples; pgstat_progress_update_multi_param(3, initprog_index, initprog_val); + /* set up our verbose error context callback */ + info.relation = onerel; + info.blkno = InvalidBlockNumber; + + callback.callback = lazy_scan_heap_cb; + callback.arg = &info; + callback.previous = error_context_stack; + error_context_stack = &callback; + /* * Except when aggressive is set, we want to skip pages that are * all-visible according to the visibility map, but only when we can skip @@ -616,6 +636,9 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, bool has_dead_tuples; TransactionId visibility_cutoff_xid = InvalidTransactionId; + /* update error callback info */ + info.blkno = blkno; + /* see note above about forcing scanning of last page */ #define FORCE_CHECK_PAGE() \ (blkno == nblocks - 1 && should_attempt_truncation(vacrelstats)) @@ -1275,6 +1298,8 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, RecordPageWithFreeSpace(onerel, blkno, freespace); } + error_context_stack = callback.previous; + /* report that everything is scanned and vacuumed */ pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED, blkno); @@ -1384,6 +1409,22 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, pfree(buf.data); } +/* + * lazy_scan_heap_cb + * Error context callback for lazy_scan_heap. + */ +static void +lazy_scan_heap_cb(void *arg) +{ + LazyScanHeapInfo *info = (LazyScanHeapInfo *) arg; + + if (info->blkno != InvalidBlockNumber) + errcontext("while scanning page %u of relation %s", + info->blkno, RelationGetRelationName(info->relation)); + else + errcontext("while vacuuming relation %s", + RelationGetRelationName(info->relation)); +} /* * lazy_vacuum_heap() -- second pass over the heap -- 2.11.0