Re: error context for vacuum to include block number

Justin Pryzby <pryzby@telsasoft.com>

From: Justin Pryzby <pryzby@telsasoft.com>
To: Masahiko Sawada <masahiko.sawada@2ndquadrant.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>, Alvaro Herrera <alvherre@2ndquadrant.com>, Andres Freund <andres@anarazel.de>, Michael Paquier <michael@paquier.xyz>, pgsql-hackers@postgresql.org
Date: 2020-03-25T04:46:51Z
Lists: pgsql-hackers
On Wed, Mar 25, 2020 at 01:34:43PM +0900, Masahiko Sawada wrote:
> I meant that with the patch, suppose that the table has 100 blocks and
> we're truncating it to 50 blocks in RelationTruncate(), the error
> context message will be "while truncating relation "aaa.bbb" to 100
> blocks", which is not correct.

> I think it should be "while truncating
> relation "aaa.bbb" to 50 blocks". We can know the relation can be
> truncated to 50 blocks by the result of count_nondeletable_pages(). So
> if we update the arguments before it we will use the number of blocks
> of relation before truncation.

Hm, yea, at that point it's:
|new_rel_pages = RelationGetNumberOfBlocks(onerel);
..so we can do better.

> My suggestion is either that we change the error message to, for
> example, "while truncating relation "aaa.bbb" having 100 blocks", or
> that we change the patch so that we can use "50 blocks" in the error
> context message.

We could do:

        update_vacuum_error_cbarg(vacrelstats,
				  VACUUM_ERRCB_PHASE_TRUNCATE,
				  InvalidBlockNumber, NULL, false);

        new_rel_pages = count_nondeletable_pages(onerel, vacrelstats);
        vacrelstats->blkno = new_rel_pages;

...

        case VACUUM_ERRCB_PHASE_TRUNCATE:
            if (BlockNumberIsValid(cbarg->blkno))
                errcontext("while truncating relation \"%s.%s\" to %u blocks",
                           cbarg->relnamespace, cbarg->relname, cbarg->blkno);
            else
                /* Error happened before/during count_nondeletable_pages() */
                errcontext("while truncating relation \"%s.%s\"",
                           cbarg->relnamespace, cbarg->relname);
            break;

-- 
Justin



Commits

  1. Avoid calls to RelationGetRelationName() and RelationGetNamespace() in

  2. Introduce vacuum errcontext to display additional information.

  3. Fix mesurement of elapsed time during truncating heap in VACUUM.

  4. Allow vacuum command to process indexes in parallel.

  5. Refactor code dedicated to index vacuuming in vacuumlazy.c

  6. Remove duplicated progress reporting during heap scan of VACUUM