pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Ranjith Ramachandra <ranjith@mammoth.io>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Seems like there is an issue with reltuples showing twice the number of rows
Date: Tue, 03 Apr 2018 10:19:23 -0400
Message-ID: <3272.1522765163@sss.pgh.pa.us> (raw)
In-Reply-To: <7d986cf7-157e-b8b3-0b01-27e96797af71@2ndquadrant.com>
References: <CAFWmNu8SfSgBWcMCaWJfDLbcFUN3riC9jDuzOd08QsJgAqv+4A@mail.gmail.com>
	<7d986cf7-157e-b8b3-0b01-27e96797af71@2ndquadrant.com>

Tomas Vondra <tomas.vondra@2ndquadrant.com> writes:
> On 04/03/2018 11:14 AM, Ranjith Ramachandra wrote:
>> it returns
>>  reltuples  | n_live_tup | n_dead_tup
>> -------------+------------+------------
>> 2.7209e+06 |    1360448 |    1360448
>> 
>> If I run analyze main_csv_0f247511f5c247c8813ba3cec90c6ae1_yf34fbb38d
>> and I run the same query again,
>>   reltuples  | n_live_tup | n_dead_tup
>> -------------+------------+------------
>>  1.36045e+06 |    1360448 |    1360448
>> 
>> But after some time the value goes back to being double the value.

> There was a difference between VACUUM and ANALYZE in handling recently
> dead rows (essentially deleted rows that can't be removed yet), causing
> similar changes to reltuples. Essentially if you do VACUUM and ANALYZE,
> it may set reltuples to rather different estimates. That is fixed now
> and should be in the next minor release.

No, I think this is the *other* thing we fixed recently: VACUUM thinks
it should set reltuples to total tuples (live + dead) whereas ANALYZE
counts only live tuples.  We did not risk back-patching that.

The question I'd ask about this case is why is there persistently 100%
bloat?  Those dead tuples should've gotten reclaimed by autovacuum.
Perhaps an open prepared transaction, or some such?

> It's probably better to use n_live_tup instead, though. I'd say that's
> closer to the "live tuples" definition.

Yeah, you might be better off looking at that, particularly since it
updates on-the-fly not just after a vacuum or analyze.

			regards, tom lane




view thread (4+ messages)  latest in thread

Message-ID: <3272.1522765163@sss.pgh.pa.us>
Permalink:  ../3272.1522765163@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3272.1522765163@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, tomas.vondra@2ndquadrant.com, ranjith@mammoth.io
  Subject: Re: Seems like there is an issue with reltuples showing twice the number of rows
  In-Reply-To: <3272.1522765163@sss.pgh.pa.us>
  References: <CAFWmNu8SfSgBWcMCaWJfDLbcFUN3riC9jDuzOd08QsJgAqv+4A@mail.gmail.com> <7d986cf7-157e-b8b3-0b01-27e96797af71@2ndquadrant.com> <3272.1522765163@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