Re: tuple statistics update

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Tom DalPozzo <t(dot)dalpozzo(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: tuple statistics update
Date: 2017-04-18 19:42:21
Message-ID: c9fe5642-eb7e-f752-a57c-d1bf04fdd0f5@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/17/2017 09:18 AM, Tom DalPozzo wrote:
> Hi, I'm using libpq to insert tuples in my table and keep looking at
> statistics through psql instead.
> I noticed that sometimes n_tuple_ins is not updated even after 1 min
> that my transaction committed.
> My libpq connection is kept alive. If I close the connection then the
> stats get updated.
> I know that stats are not instantaneous, but I thought that after a
> while that a transaction is committed it would be updated.

Any of this apply?:

https://www.postgresql.org/docs/9.6/static/monitoring-stats.html

"Another important point is that when a server process is asked to
display any of these statistics, it first fetches the most recent report
emitted by the collector process and then continues to use this snapshot
for all statistical views and functions until the end of its current
transaction. So the statistics will show static information as long as
you continue the current transaction. Similarly, information about the
current queries of all sessions is collected when any such information
is first requested within a transaction, and the same information will
be displayed throughout the transaction. This is a feature, not a bug,
because it allows you to perform several queries on the statistics and
correlate the results without worrying that the numbers are changing
underneath you. But if you want to see new results with each query, be
sure to do the queries outside any transaction block. Alternatively, you
can invoke pg_stat_clear_snapshot(), which will discard the current
transaction's statistics snapshot (if any). The next use of statistical
information will cause a new snapshot to be fetched."

> Regards
> Pupillo
>
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-04-18 20:06:18 Re: tuple statistics update
Previous Message Jeff Janes 2017-04-18 16:51:53 Re: # of connections and architecture design