Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0d6B-00079o-IC for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 01:40:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0d67-00021o-Ck for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 01:40:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0d66-00021G-VS for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 01:40:39 +0000 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g0d5z-0002oC-SX for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 01:40:37 +0000 Received: by mail-it0-x241.google.com with SMTP id h3-v6so601637ita.2 for ; Thu, 13 Sep 2018 18:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:message-id:from:date:subject:to :cc; bh=lbOp2SK02DZHS5R5D/lm8B7ItuQDLivGs0jkhKZLxOA=; b=tPlM4w4C9I3aAmm5/ORpIMyKBYdhG3hK101a93dPfJHERWMHAbKKbUwmGOv2o+E08k 77PiYUBBsbqxePxhOnHGv48JkytC0/sl68h5k8E/iGN/n+B4Vyj3lB61uhN+H6+C1D5Q 6DeUlcoRh1d4VgUM1ArksE5DFM8BjLpV/0NfEBMX8kPLydsArBnS1bSYMDIqKgIKs5Ug sbXz70HB6nYHJkpOFTTEVZbSoAbGqLd7GEsL+CL6G7uB3I6k3QUZVK3nAjR5nwqSjEoq 6A0qL5Xe1ufez9gc5LS6E23s2oag8XDJ+35kYtWjHFcuNQVmWvJ+aTuaUkUyp8HYihSB WL5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:message-id :from:date:subject:to:cc; bh=lbOp2SK02DZHS5R5D/lm8B7ItuQDLivGs0jkhKZLxOA=; b=syENWbfeyJGj9j0zlnvmUm3bOd77inZE4t7q3WD99nVa2mw6A1yTHmTbSbgHWMdw4A FVHuJc+TKBBDgJBTzYJWe+TAt2YqZjYt79UBKEeqieVf+BPRFsEwntmRCdJtGXEFGne6 RXNv87UjKdP8tlc1hK6L6+q811KhigZUqXzZmOmEhu3e9YEF4VqsUXmBqXPATkmXwTRj QoRAB3F+rg2g9qxEjNquokCaGCcjuCn0asmXIwJ9KoXl69GqmkkEZQUL/9vhOl21fUlY UUEzjv0lKeSffx+i5gLLrGILO0Gsh45KUX+0ddiL7YxYtX58SKIaO4TeqSQuXbonmLbD VD5A== X-Gm-Message-State: APzg51CmsBhzjGPzfwTDdlppMfWKIREslD+RqjEJTzg5XDGzTayLgO13 m509S/Go+yX/2tyH0azglodh5eMY X-Google-Smtp-Source: ANB0VdavR2lZbZ1iXqDsc5NB3AhktY4animFu/cDyCmTlmih/dkKh5f/xSfBIdUjI6gPgVu/H7rL/Q== X-Received: by 2002:a24:22cf:: with SMTP id o198-v6mr627312ito.53.1536889230052; Thu, 13 Sep 2018 18:40:30 -0700 (PDT) Received: from localhost (48.158.155.104.bc.googleusercontent.com. [104.155.158.48]) by smtp.gmail.com with ESMTPSA id n198-v6sm197427itn.36.2018.09.13.18.40.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Sep 2018 18:40:29 -0700 (PDT) Mime-Version: 1.0 In-Reply-To: <11505.1536884478@sss.pgh.pa.us> References: <11505.1536884478@sss.pgh.pa.us> Message-ID: <5b9b0f243f8b8f4e0c000004@polymail.io> From: =?UTF-8?q?Mart=C3=ADn_Fern=C3=A1ndez?= Date: Thu, 13 Sep 2018 18:40:19 -0700 X-Mailer: Polymail Subject: Re: Behaviour when autovacuum is canceled To: "Tom Lane" Cc: "David G. Johnston" , "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary=a3d10e746f7f80bc39a98cbb7423a6f14db4058c135d539b2b64ea644bda List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --a3d10e746f7f80bc39a98cbb7423a6f14db4058c135d539b2b64ea644bda Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Tom, Thanks for the detailed explanation. I can start mapping your explanation w= ith the source code I've been reading :) We are in the process of tuning our autovacuum settings (on some tables) an= d stop relying on crontabs that are performing manual vacuums.=C2=A0 By performing this changes we are going to start relying more heavily on th= e autovacuum work and the concern of "lost work" caused by autovacuum cance= ling itself when locking contention happen showed up. I'm guessing that we = might be over thinking this and the canceling is not going to happen as fre= quently as we think it will. Mart=C3=ADn On Thu, Sep 13th, 2018 at 9:21 PM, Tom Lane wrote: >=20 >=20 >=20 > =3D?UTF-8?q?Mart=3DC3=3DADn_Fern=3DC3=3DA1ndez?=3D < fmartin91@gmail.com = > writes: > > We basically started a VACUUM on a given table, waited for one index to > process (captured cleaned rows count) and cancel the VACUUM. When we run > another VACUUM on the same table the dead rows removed from the first > index was a number slightly higher than the value logged on the first > VACUUM. This behaviour made us feel that the work done to clean dead > tuples on the first index was performed again.=C2=A0 >=20 > The unit of work that doesn't have to be repeated if VACUUM is canceled > is: >=20 > 1. Scan a bunch of heap pages to identify dead tuples; > 2. Scan *all* the table's indexes to remove the corresponding index > entries; > 3. Rescan those heap pages to actually remove the tuples. >=20 > It sounds like you canceled partway through phase 2. >=20 > The actual size of this unit of work is the number of dead-tuple TIDs > that will fit in maintenance_work_mem (at six or eight bytes apiece, > I forget whether it's aligned...). Normally, people make > maintenance_work_mem big so that they can reduce the number of index > scan cycles needed to complete vacuuming a table. But if you're > concerned about reducing the amount of work lost to a cancel, > you might try *reducing* maintenance_work_mem. This will make > vacuum slower overall (more index scans), but you have a better > chance that it will manage to actually remove some tuples before > getting canceled. >=20 > Or you could look at fixing the access patterns that are causing > so many autovacuum cancels. >=20 > regards, tom lane >=20 >=20 >=20 > --a3d10e746f7f80bc39a98cbb7423a6f14db4058c135d539b2b64ea644bda Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 3D""
Tom,

Thanks for the detailed expla= nation. I can start mapping your explanation with the source code I've been= reading :)

We are in the process of tuning our autovacuum settings = (on some tables) and stop relying on crontabs that are performing manual va= cuums. 

By performing t= his changes we are going to start relying more heavily on the autovacuum wo= rk and the concern of "lost work" caused by autovacuum canceling itself whe= n locking contention happen showed up. I'm guessing that we might be over t= hinking this and the canceling is not going to happen as frequently as we t= hink it will.

Mart=C3=ADn

On Thu, Sep 13th, 2018 at 9:21 PM, Tom Lane <tgl@sss.pgh.p= a.us> wrote:

=3D?UTF-8?q?Mart=3DC3=3DADn_Fern=3DC3=3DA1ndez?=3D <fmartin91@gmail.com> writes:
> We basically started a VACUUM on a given table, waited for one ind= ex to process (captured cleaned rows count) and cancel the VACUUM. When we = run another VACUUM on the same table the dead rows removed from the first i= ndex was a number slightly higher than the value logged on the first VACUUM= . This behaviour made us feel that the work done to clean dead tuples on th= e first index was performed again. 

The unit of work that doesn't have to be repeated if VACUUM is canceled
is:

1. Scan a bunch of heap pages to identify dead tuples;
2. Scan *all* the table's indexes to remove the corresponding index ent= ries;
3. Rescan those heap pages to actually remove the tuples.

It sounds like you canceled partway through phase 2.

The actual size of this unit of work is the number of dead-tuple TIDs
that will fit in maintenance_work_mem (at six or eight bytes apiece,
I forget whether it's aligned...). Normally, people make
maintenance_work_mem big so that they can reduce the number of index
scan cycles needed to complete vacuuming a table. But if you're
concerned about reducing the amount of work lost to a cancel,
you might try *reducing* maintenance_work_mem. This will make
vacuum slower overall (more index scans), but you have a better
chance that it will manage to actually remove some tuples before
getting canceled.

Or you could look at fixing the access patterns that are causing
so many autovacuum cancels.

regards, tom lane


--a3d10e746f7f80bc39a98cbb7423a6f14db4058c135d539b2b64ea644bda--