Thread: Does cancelling autovacuum make you lose all the work it did?
I have a long running autovacuum (to prevent wraparound) that has been doing on for 6 days. I’m considering changing the autovacuum settings to be more aggressive, cancelling the current one, and then let it restart. Would the tuples its cleaned be lost if I did this?
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.
Hi Greg,
No autovacuum or vacuum causes no user-visible or breaking changes of any kind … it does change the performance of the database backend, but that’s all.
--Stephen
From: Greg Rychlewski (LCL) <Greg.Rychlewski@loblaw.ca>
Sent: Friday, June 12, 2020 04:19
To: pgsql-novice@postgresql.org
Subject: Does cancelling autovacuum make you lose all the work it did?
I have a long running autovacuum (to prevent wraparound) that has been doing on for 6 days. I’m considering changing the autovacuum settings to be more aggressive, cancelling the current one, and then let it restart. Would the tuples its cleaned be lost if I did this?
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.
No autovacuum or vacuum causes no user-visible or breaking changes of any kind … it does change the performance of the database backend, but that’s all.
"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
Re: [EXT] Re: Does cancelling autovacuum make you lose all the workit did?
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.
"Greg Rychlewski (LCL)" <Greg.Rychlewski@loblaw.ca> writes: > 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? No ... ongoing transactions could be creating new dead rows. IIRC, a vacuum won't report its removal of dead rows to the stats collector till the very end, so what I'd expect is a big drop when it finishes. (I am not sure offhand what happens to those stats if you cancel the vacuum partway through --- it might report nothing, causing the stats to be way off until the next successful vacuum.) regards, tom lane