Re: Skip index cleanup if autovacuum did not do any work

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Feike Steenbergen <feikesteenbergen(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Skip index cleanup if autovacuum did not do any work
Date: 2017-11-28 21:55:03
Message-ID: 10963.1511906103@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Feike Steenbergen <feikesteenbergen(at)gmail(dot)com> writes:
> On a server with a very frequent xid wraparound I can see that the
> anti-wraparound vacuum is finished very quickly with the heap, yet it still
> scans all the indexes, which causes it to still have to read a lot of data,
> which takes a considerable amount of time.

> I dove into the code a bit and as far as I can tell, all the time spent for
> doing this is is in lazy_cleanup_index.

> For the very specific use case of all-frozen, basically read-only tables,
> would it be ok to skip the lazy_cleanup_index call? As we are sure we did
> not touch the heap or the index, I'd say a cleanup may not be necessary.

It's intentional that we call the index AM in any case. Your patch
entirely forecloses the possibility that the AM might have work it
wants to do at VACUUM time independently of whether there were any
dead heap tuples. (A handy example is GIN pushing stuff from its
fast-insert queue to the main index structure.)

It might be okay to put such a short-circuit in at a lower level,
eg within the btree AM. I don't remember at the moment whether
a btree vacuum scan accomplishes anything much if there are no dead
tuples.

One thing that I think it does do is update the index's pg_class stats
(relpages/reltuples). Maybe it's okay to skip that in this particular
scenario, trusting that auto-analyze would fix it, but that seems
worthy of debate.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2017-11-28 22:00:39 Re: Skip index cleanup if autovacuum did not do any work
Previous Message Feike Steenbergen 2017-11-28 21:54:32 Re: Skip index cleanup if autovacuum did not do any work