pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: Nicola Contu <nicola.contu@gmail.com>
Cc: Rene Romero Benavides <rene.romero.b@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Cc: Alessandro.aste@gtt.net
Subject: Re: pgstattuple free_percent to high
Date: Thu, 14 Dec 2017 10:13:05 -0500
Message-ID: <20171214151305.GY4628@tamriel.snowman.net> (raw)
In-Reply-To: <CAMTZZh08UX+=LpY_a4HjAj=Gqa6n_Xhxf0wYgP9Fmegc=W1KgQ@mail.gmail.com>
References: <CAMTZZh3vNp_2LBkC8HHHKrSQ0J0nD8w23RdiKuuQFmKZW79ovA@mail.gmail.com>
	<CANaGW08JHVGrmP2BoJV3A8Y1JqGpF0F7SK4u6Cnx-HHWRXckjA@mail.gmail.com>
	<CAMTZZh08UX+=LpY_a4HjAj=Gqa6n_Xhxf0wYgP9Fmegc=W1KgQ@mail.gmail.com>

Greetings Nicola,

* Nicola Contu (nicola.contu@gmail.com) wrote:
> I think tuning the autovacuum settings may increase performances and remove
> dead_tuples but as far as I know, the autovacuum runs a vacuum analyze.
> The vacuum analyze won't touch the free_percent of the table.

That's not entirely accurate.  If all of the free space is at the *end*
of the relation then autovacuum will attempt to lock the relation and
truncate the table to give that free space back to the OS.

On a table where all of the rows are regularly updated, eventually the
"live" data should end up towards the front of the relation and the end
of the relation will be all dead tuples, allowing the truncate to
happen.  If you have tuples at the end of the relation that aren't ever
updated but they're "live" then we won't be able to truncate.

The pg_freespacemap extension can be useful to see where the free space
is in the relation.

There are a few tools out there that aren't part of core PostgreSQL that
you could consider using such as pg_repack and pg_squeeze.

> So I'm trying to find a way to adjust the free percent for some tables
> without doing a manually full vacuum.
> We are now monitoring the free percent, so we may find the part of the code
> that can increase that value, but was wondering if there is anything on the
> postgres side to resolve this problem.

Having some free space in the relation isn't a 'problem' and is a good
thing because it means that new rows (from either INSERTs or UPDATEs)
have a place to go that doesn't require extending the relation (which
requires an additional lock as well as some additional work).  As for
how much free space is good to have and how much is too much depends on
the specific workload.

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

view thread (6+ messages)  latest in thread

Message-ID: <20171214151305.GY4628@tamriel.snowman.net>
Permalink:  ../20171214151305.GY4628@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20171214151305.GY4628@tamriel.snowman.net

 · 

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: sfrost@snowman.net, nicola.contu@gmail.com, rene.romero.b@gmail.com, Alessandro.aste@gtt.net
  Subject: Re: pgstattuple free_percent to high
  In-Reply-To: <20171214151305.GY4628@tamriel.snowman.net>
  References: <CAMTZZh3vNp_2LBkC8HHHKrSQ0J0nD8w23RdiKuuQFmKZW79ovA@mail.gmail.com> <CANaGW08JHVGrmP2BoJV3A8Y1JqGpF0F7SK4u6Cnx-HHWRXckjA@mail.gmail.com> <CAMTZZh08UX+=LpY_a4HjAj=Gqa6n_Xhxf0wYgP9Fmegc=W1KgQ@mail.gmail.com> <20171214151305.GY4628@tamriel.snowman.net>

* 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