Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZMzXj-0005M9-9Q for pgsql-admin@arkaria.postgresql.org; Wed, 05 Aug 2015 14:19:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZMzXi-0006GG-Rr for pgsql-admin@arkaria.postgresql.org; Wed, 05 Aug 2015 14:19:42 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZMzW5-0002Bc-0b for pgsql-admin@postgresql.org; Wed, 05 Aug 2015 14:18:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZMzW1-0006iA-PN for pgsql-admin@postgresql.org; Wed, 05 Aug 2015 14:17:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t75EHtSm009875; Wed, 5 Aug 2015 10:17:55 -0400 From: Tom Lane To: John Scalia cc: "pgsql-admin@postgresql.org" Subject: Re: Query runs on 9.2, but not on 9.4 In-reply-to: References: Comments: In-reply-to John Scalia message dated "Wed, 05 Aug 2015 08:56:02 -0500" Date: Wed, 05 Aug 2015 10:17:55 -0400 Message-ID: <9874.1438784275@sss.pgh.pa.us> X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org John Scalia 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 -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin