pg_class.reltuples VS pg_stat_all_tables.n_live_tup for estimation of table

From: William Dunn <dunnwjr(at)gmail(dot)com>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: pg_class.reltuples VS pg_stat_all_tables.n_live_tup for estimation of table
Date: 2015-06-17 19:14:27
Message-ID: CAEva=V=bNb6rBZH_AuXQ19pFXqAoyKdRjyFKeR93ckdkXQdgsQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

Does anyone which is a more accurate estimate of a table's live
rows: pg_class.reltuples (
http://www.postgresql.org/docs/current/static/catalog-pg-class.html)
OR pg_stat_all_tables.n_live_tup (
http://www.postgresql.org/docs/current/static/monitoring-stats.html#PG-STAT-ALL-TABLES-VIEW)?
In my test database their values are not the same.

- Is pg_class.reltuples an estimation of live tuples only, or is it of
all tuples (both live and dead)? I would guess it's live only but that is a
guess
- In the database I am testing:
- pg_class.reltuples <> pg_stat_all_tables.n_live_tup
- pg_class.reltuples <> (pg_stat_all_tables.n_live_tup
+ pg_stat_all_tables.n_dead_tup)

I understand that pg_stat_all_tables is probably the more expensive view to
query but I am already querying both so I only care which is more accurate.

Thanks!
Will

*Will J. Dunn*
*willjdunn.com <http://willjdunn.com>*

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2015-06-17 19:48:36 Re: pg_class.reltuples VS pg_stat_all_tables.n_live_tup for estimation of table
Previous Message Jony Cohen 2015-06-17 19:10:46 Index Advice in PG