Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1idGOF-0007fC-CX for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Dec 2019 16:23:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1idGOE-0002O2-2W for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Dec 2019 16:23:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1idGOD-0002Nu-HM for pgsql-hackers@lists.postgresql.org; Fri, 06 Dec 2019 16:23:33 +0000 Received: from mail-yw1-xc34.google.com ([2607:f8b0:4864:20::c34]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1idGOA-0008Bm-2o for pgsql-hackers@postgresql.org; Fri, 06 Dec 2019 16:23:32 +0000 Received: by mail-yw1-xc34.google.com with SMTP id 192so2906587ywy.0 for ; Fri, 06 Dec 2019 08:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UqbV45wPTcq41XYg8DaNeSG1PJAG+HPtSepIrAGCgGk=; b=0BcecJ7qHoEFcsKFrjJqI4DFQI07ODKQXdOl3vmfxd5+vpS6yUbqxJmufPuxjqWmRe KrLRPTXmxk4FGiNuJ8kbaXu7zoztAlDy4cYTipIKdVKENdIUo8fYQ92yoKxqFM+6J3nm TPFaqSoSlY9PsGjVY5EcDPDAmPkvDy8WImERc7kURIKBefDKsgFS/c/DJWsqAcU5XjwZ SB+AtuKpI04GKcQCFqSGaOic3rRCsW0OHbP4ZpPU0CRpXn/CSfleeoG8kWPQ8O88V6aY XFm3e/L5yy5f63duaCIszb/99D7nVOlE3Tc9yT4gzE9ijc6t3+tRoV9NmljesT7HxDR3 PCvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UqbV45wPTcq41XYg8DaNeSG1PJAG+HPtSepIrAGCgGk=; b=jtBFc6+mSXOglN/Om4zNFtqthwHuVZop6nP6uqJZyMS4aVcq1bAWOcoNnjwTSLX67I OwTzyQOPXfjc41pI29/PESZgZuHmrlIZktTXkZspGvydWJh6hj5zBf/XC5HS/B7GIcs/ ByNcn5BtapKA0Z5/Y7LCBBOqJpAXqI54hFcC+1JJurkd89qqW7nwK4koK3DhX4vuz5+W Th/OCWZqsyUQC6mW2He7Xd69qMEF2qMYF4zRsbnjEVchJQZ0iusAib34NFm2nEJyKRs7 WTjMk0m0EaNIK3pQHcEUIPNGTzSwXm3l92flOlX1VqPoyTVG3K8QEuaPATkwxJod/E8U KWYQ== X-Gm-Message-State: APjAAAXbWGLOLM+JCt28EoGfjdCyeupCdRpylPSAjeS/MExxeSSq5S8H YvYRAgFyQN2x6ue2SlNSzaRgh2a1nu4= X-Google-Smtp-Source: APXvYqyzZ/peWEYc79bqCSxYvracsfmawBjoeWQkZzsENIB7FXxXHlyKwGVDeUHrY2mCuzmKkqK71Q== X-Received: by 2002:a0d:f882:: with SMTP id i124mr8804923ywf.126.1575649407916; Fri, 06 Dec 2019 08:23:27 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 199sm6346323ywn.52.2019.12.06.08.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 08:23:26 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 5314580096B; Fri, 6 Dec 2019 10:23:25 -0600 (CST) Date: Fri, 6 Dec 2019 10:23:25 -0600 From: Justin Pryzby To: pgsql-hackers@postgresql.org Cc: Andres Freund Subject: Re: error context for vacuum to include block number Message-ID: <20191206162325.GQ2082@telsasoft.com> References: <20191120210600.GC30362@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="f0KYrhQ4vYSV2aJu" Content-Disposition: inline In-Reply-To: <20191120210600.GC30362@telsasoft.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --f0KYrhQ4vYSV2aJu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Find attached updated patch: . Use structure to include relation name. . Split into a separate patch rename of "StringInfoData buf". 2019-11-27 20:04:53.640 CST [14244] ERROR: canceling statement due to statement timeout 2019-11-27 20:04:53.640 CST [14244] CONTEXT: block 2314 of relation t 2019-11-27 20:04:53.640 CST [14244] STATEMENT: vacuum t; I tried to use BufferGetTag() to avoid using a 2ndary structure, but fails if the buffer is not pinned. --f0KYrhQ4vYSV2aJu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-vacuum-errcontext-to-show-block-being-processed.patch" From 41e1d6d118346e84aac7cfe68424f7452c7dcb8d Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 20 Nov 2019 14:53:20 -0600 Subject: [PATCH v2 1/2] vacuum errcontext to show block being processed As requested here. https://www.postgresql.org/message-id/20190807235154.erbmr4o4bo6vgnjv%40alap3.anarazel.de --- src/backend/access/heap/vacuumlazy.c | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index a3c4a1d..774cad5 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -138,6 +138,11 @@ typedef struct LVRelStats bool lock_waiter_detected; } LVRelStats; +typedef struct +{ + char *relname; + BlockNumber blkno; +} vacuum_error_callback_arg; /* A few variables that don't seem worth passing around as parameters */ static int elevel = -1; @@ -175,6 +180,7 @@ static bool lazy_tid_reaped(ItemPointer itemptr, void *state); static int vac_cmp_itemptr(const void *left, const void *right); static bool heap_page_is_all_visible(Relation rel, Buffer buf, TransactionId *visibility_cutoff_xid, bool *all_frozen); +static void vacuum_error_callback(void *arg); /* @@ -524,6 +530,8 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, PROGRESS_VACUUM_MAX_DEAD_TUPLES }; int64 initprog_val[3]; + ErrorContextCallback errcallback; + vacuum_error_callback_arg cbarg; pg_rusage_init(&ru0); @@ -635,6 +643,14 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, else skipping_blocks = false; + /* Setup error traceback support for ereport() */ + errcallback.callback = vacuum_error_callback; + cbarg.relname = relname; + cbarg.blkno = 0; /* Not known yet */ + errcallback.arg = (void *) &cbarg; + errcallback.previous = error_context_stack; + error_context_stack = &errcallback; + for (blkno = 0; blkno < nblocks; blkno++) { Buffer buf; @@ -657,6 +673,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, (blkno == nblocks - 1 && should_attempt_truncation(params, vacrelstats)) pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED, blkno); + cbarg.blkno = blkno; if (blkno == next_unskippable_block) { @@ -817,6 +834,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, buf = ReadBufferExtended(onerel, MAIN_FORKNUM, blkno, RBM_NORMAL, vac_strategy); + // errcallback.arg = (void *) &buf; /* We need buffer cleanup lock so that we can prune HOT chains. */ if (!ConditionalLockBufferForCleanup(buf)) @@ -1388,6 +1406,9 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, RecordPageWithFreeSpace(onerel, blkno, freespace); } + /* Pop the error context stack */ + error_context_stack = errcallback.previous; + /* report that everything is scanned and vacuumed */ pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED, blkno); @@ -2354,3 +2375,22 @@ heap_page_is_all_visible(Relation rel, Buffer buf, return all_visible; } + +/* + * Error context callback for errors occurring during vacuum. + */ +static void +vacuum_error_callback(void *arg) +{ + vacuum_error_callback_arg *cbarg = arg; + errcontext("block %u of relation %s", cbarg->blkno, cbarg->relname); + // Buffer *buf = arg; + // RelFileNode rnode; + // ForkNumber forknum; + // BlockNumber blknum; + // char *path; + // BufferGetTag(*buf, &rnode, &forknum, &blknum); + // path = relpathperm(rnode, forknum); + // errcontext("block %u of relation %s", blknum, path); + // pfree(path); +} -- 2.7.4 --f0KYrhQ4vYSV2aJu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0002-Rename-buf-to-avoid-shadowing-buf-of-another-type.patch" From db5cf19bc6d29eb8b9cb5cf251abc8d2a18e97dc Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 27 Nov 2019 20:07:10 -0600 Subject: [PATCH v2 2/2] Rename buf to avoid shadowing buf of another type --- src/backend/access/heap/vacuumlazy.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 774cad5..e17c4cc 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -523,7 +523,7 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, BlockNumber next_unskippable_block; bool skipping_blocks; xl_heap_freeze_tuple *frozen; - StringInfoData buf; + StringInfoData sbuf; const int initprog_index[] = { PROGRESS_VACUUM_PHASE, PROGRESS_VACUUM_TOTAL_HEAP_BLKS, @@ -1502,33 +1502,33 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats, * This is pretty messy, but we split it up so that we can skip emitting * individual parts of the message when not applicable. */ - initStringInfo(&buf); - appendStringInfo(&buf, + initStringInfo(&sbuf); + appendStringInfo(&sbuf, _("%.0f dead row versions cannot be removed yet, oldest xmin: %u\n"), nkeep, OldestXmin); - appendStringInfo(&buf, _("There were %.0f unused item identifiers.\n"), + appendStringInfo(&sbuf, _("There were %.0f unused item identifiers.\n"), nunused); - appendStringInfo(&buf, ngettext("Skipped %u page due to buffer pins, ", + appendStringInfo(&sbuf, ngettext("Skipped %u page due to buffer pins, ", "Skipped %u pages due to buffer pins, ", vacrelstats->pinskipped_pages), vacrelstats->pinskipped_pages); - appendStringInfo(&buf, ngettext("%u frozen page.\n", + appendStringInfo(&sbuf, ngettext("%u frozen page.\n", "%u frozen pages.\n", vacrelstats->frozenskipped_pages), vacrelstats->frozenskipped_pages); - appendStringInfo(&buf, ngettext("%u page is entirely empty.\n", + appendStringInfo(&sbuf, ngettext("%u page is entirely empty.\n", "%u pages are entirely empty.\n", empty_pages), empty_pages); - appendStringInfo(&buf, _("%s."), pg_rusage_show(&ru0)); + appendStringInfo(&sbuf, _("%s."), pg_rusage_show(&ru0)); ereport(elevel, (errmsg("\"%s\": found %.0f removable, %.0f nonremovable row versions in %u out of %u pages", RelationGetRelationName(onerel), tups_vacuumed, num_tuples, vacrelstats->scanned_pages, nblocks), - errdetail_internal("%s", buf.data))); - pfree(buf.data); + errdetail_internal("%s", sbuf.data))); + pfree(sbuf.data); } -- 2.7.4 --f0KYrhQ4vYSV2aJu--