Re: Query runs on 9.2, but not on 9.4

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: John Scalia <jayknowsunix(at)gmail(dot)com>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Query runs on 9.2, but not on 9.4
Date: 2015-08-05 14:17:55
Message-ID: 9874.1438784275@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

John Scalia <jayknowsunix(at)gmail(dot)com> writes:
> I've got a query I use to show the amount of shared buffers in use that is
> giving me some issues. It uses the pg_buffercache extension. The query is:

> SELECT
> c.relname,
> pg_size_pretty(count(*) * 8192) as buffered,
> round(100.0 * count(*) /
> (SELECT setting FROM pg_settings
> WHERE name='shared_buffers')::integer,1)
> AS buffers_percent,
> round(100.0 * count(*) * 8192 /
> pg_relation_size(c.oid),1)
> AS percent_of_relation
> FROM pg_class c
> INNER JOIN pg_buffercache b
> ON b.relfilenode = c.relfilenode
> INNER JOIN pg_database d
> ON (b.reldatabase = d.oid AND d.datname = current_database())
> GROUP BY c.oid,c.relname
> ORDER BY 3 DESC
> LIMIT 25;

> On a 9.2 system, it runs fine and produces a list of the top 25 tables
> using the shared buffer, but on 9.3 and above, it throw a "division by
> zero" error.

It seems likely that you have at least one table in the 9.4 system for
which pg_relation_size() produces 0, but on the 9.2 system that table is
not there or is not physically zero-length.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message John Scalia 2015-08-05 14:18:33 Re: Query runs on 9.2, but not on 9.4
Previous Message Vasilis Ventirozos 2015-08-05 14:16:54 Re: Query runs on 9.2, but not on 9.4