pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Martín Fernández <fmartin91@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Behaviour when autovacuum is canceled
Date: Thu, 13 Sep 2018 20:21:18 -0400
Message-ID: <11505.1536884478@sss.pgh.pa.us> (raw)
In-Reply-To: <5b9aee4e3f8b8f4e0c000003@polymail.io>
References: <5b9aebc53f8b8f4e0c000002@polymail.io>
	<5b9aee4e3f8b8f4e0c000003@polymail.io>

=?UTF-8?q?Mart=C3=ADn_Fern=C3=A1ndez?= <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. 

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 entries;
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




view thread (8+ messages)  latest in thread

Message-ID: <11505.1536884478@sss.pgh.pa.us>
Permalink:  ../11505.1536884478@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11505.1536884478@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fmartin91@gmail.com, david.g.johnston@gmail.com
  Subject: Re: Behaviour when autovacuum is canceled
  In-Reply-To: <11505.1536884478@sss.pgh.pa.us>
  References: <5b9aebc53f8b8f4e0c000002@polymail.io> <5b9aee4e3f8b8f4e0c000003@polymail.io> <11505.1536884478@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox