Re: [EXT] Re: Does cancelling autovacuum make you lose all the workit did? - Mailing list pgsql-novice

From Greg Rychlewski (LCL)
Subject Re: [EXT] Re: Does cancelling autovacuum make you lose all the workit did?
Date
Msg-id B57DD9EC-BBF8-4712-8DA2-0574D4412ED5@loblaw.ca
Whole thread Raw
In response to Re: Does cancelling autovacuum make you lose all the work it did?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [EXT] Re: Does cancelling autovacuum make you lose all the work it did?  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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_typeare null. One thing I noticed though is that n_dead_tup in pg_stat_all_tables either stays the same or
goesup. Should this be going down during the autovacuum?
 

On 2020-06-12, 4:33 PM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote:

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

    "David G. Johnston" <david.g.johnston@gmail.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.
Ifyou received this message in error or are not the intended recipient, you should destroy the email message and any
attachmentsor 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
exclusifdu destinataire. Si vous recevez ce message par erreur ou si vous n’en êtes pas le destinataire prévu, vous
devezdétruire le message et toute pièce jointe ou copie et vous êtes tenu de ne pas conserver, distribuer, divulguer ni
utilisertout renseignement qu’il contient. Veuillez nous informer de toute erreur d’envoi en répondant à ce message.
Mercide votre collaboration.
 

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Does cancelling autovacuum make you lose all the work it did?
Next
From: Tom Lane
Date:
Subject: Re: [EXT] Re: Does cancelling autovacuum make you lose all the work it did?