Re: db stats vs table stats

From: "Ed L(dot)" <pgsql(at)bluepolka(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: db stats vs table stats
Date: 2007-02-23 23:38:30
Message-ID: 200702231638.30839.pgsql@bluepolka.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday February 23 2007 3:06 pm, Ed L. wrote:
> > I've been periodically collecting the stats stored in
> > pg_statio_all_tables and pg_stat_database for ~30 different
> > clusters, and have noticed a curiosity... The table-level IO stats
> > appear to be typically 1-2 orders of magnitude larger than
> > the db-level stats. Can anyone explain that?

Here's an example of how I'm calculating the deltas. Perhaps
someone can spot an error or mistaken assumption. In this
case, the deltas are not orders of magnitude out of sync
with each other, but they grew from about 3% out of sync to
45% out of sync in ~35 minutes on a DB with 500 transactions/
second.

drop table s;
create table s as
select now(), blks_read as db_blks_read,
sum(case when heap_blks_read ISNULL then 0 else heap_blks_read end +
case when idx_blks_read ISNULL then 0 else idx_blks_read end +
case when toast_blks_read ISNULL then 0 else toast_blks_read end +
case when tidx_blks_read ISNULL then 0 else tidx_blks_read end) as table_blks_read
from pg_stat_database sd, pg_database d, pg_class c, pg_statio_all_tables st
where sd.datname = d.datname
and d.datname = current_database()
and c.oid = st.relid
group by blks_read;

create or replace view delta_view as
select now() - s.now as delta, blks_read - s.db_blks_read as db_blks_read_delta,
sum(case when heap_blks_read ISNULL then 0 else heap_blks_read end +
case when idx_blks_read ISNULL then 0 else idx_blks_read end +
case when toast_blks_read ISNULL then 0 else toast_blks_read end +
case when tidx_blks_read ISNULL then 0 else tidx_blks_read end) -
s.table_blks_read as table_blks_read_delta
from pg_stat_database sd, pg_database d, pg_class c, pg_statio_all_tables st, s
where sd.datname = d.datname
and d.datname = current_database()
and c.oid = st.relid
group by blks_read, s.now, db_blks_read, table_blks_read;

select * from delta_view;

delta | db_blks_read_delta | table_blks_read_delta
-----------------+--------------------+-----------------------
00:32:51.007703 | 384243 | 556212
(1 row)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-02-23 23:47:52 Re: pg_autovacuum should allow NULL values
Previous Message Bruce Momjian 2007-02-23 23:32:07 Re: 5 Weeks till feature freeze or (do you know where your patch is?)