Re: [EXT] Re: Does cancelling autovacuum make you lose all the work it did?

From: "Greg Rychlewski (LCL)" <Greg(dot)Rychlewski(at)loblaw(dot)ca>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Stephen Froehlich <s(dot)froehlich(at)cablelabs(dot)com>, "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [EXT] Re: Does cancelling autovacuum make you lose all the work it did?
Date: 2020-06-13 00:32:14
Message-ID: B57DD9EC-BBF8-4712-8DA2-0574D4412ED5@loblaw.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi Tom,

Thanks for your reply. Regarding it being blocked, I don't think it is but I could be wrong. Both wait_event and wait_event_type are null. One thing I noticed though is that n_dead_tup in pg_stat_all_tables either stays the same or goes up. Should this be going down during the autovacuum?

On 2020-06-12, 4:33 PM, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

CAUTION: External email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> To answer the original question: vacuum's effects are basically immediate
> so work is not lost if it gets cancelled.

Mmm ... not entirely true. vacuum does a cycle like this:

1. scan table looking for removable rows; remember their TIDs

2. when memory for said TIDs is full, make a pass over the table's
indexes to find and delete index entries pointing at those TIDs

3. then, go back to the heap pages and actually remove the rows

4. if we didn't reach the end of the table yet, return to step 1.

If we get cancelled at any point, the data structure is still
consistent; there may be heap rows that don't have a full set
of index entries, but that doesn't matter because nobody cares
about finding those entries from the indexes. However, when
you redo the vacuum, it'll have to redo some of the work from
the current cycle, depending on exactly how far along it was
when you cancelled it. At the very least it's going to be
repeating some heap-scanning work, though that's the cheapest
part of this because it's basically read-only. The most
expensive parts are the actual index and heap tuple removals,
and any one of those won't need to be done over.

The size of the cycles depends on maintenance_work_mem; so if
you have that set really large, you can lose more time than
if it's not so large.

TBH, though, are you sure the vacuum is doing work and not
just blocked waiting for somebody else? An autovac can be
blocked indefinitely by some other query holding a table-level
or page-level lock. Check its state in pg_stat_activity.

regards, tom lane

This email message is confidential, may be legally privileged and is intended for the exclusive use of the addressee. If you received this message in error or are not the intended recipient, you should destroy the email message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained. Please inform us of the delivery error by return email. Thank you for your cooperation.

Le présent message électronique est confidentiel et peut être couvert par le secret professionnel. Il est à l’usage exclusif du destinataire. Si vous recevez ce message par erreur ou si vous n’en êtes pas le destinataire prévu, vous devez détruire le message et toute pièce jointe ou copie et vous êtes tenu de ne pas conserver, distribuer, divulguer ni utiliser tout renseignement qu’il contient. Veuillez nous informer de toute erreur d’envoi en répondant à ce message. Merci de votre collaboration.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2020-06-13 03:18:28 Re: [EXT] Re: Does cancelling autovacuum make you lose all the work it did?
Previous Message Tom Lane 2020-06-12 20:33:46 Re: Does cancelling autovacuum make you lose all the work it did?