Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id BB58A632D1A for ; Sun, 20 Jun 2010 12:34:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 46205-09 for ; Sun, 20 Jun 2010 15:34:45 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id B2FEB632B87 for ; Sun, 20 Jun 2010 12:34:45 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o5KFYf6K025290; Sun, 20 Jun 2010 11:34:42 -0400 (EDT) To: Dave Crooke cc: venu madhav , pgsql-performance@postgresql.org Subject: Re: Obtaining the exact size of the database. In-reply-to: References: Comments: In-reply-to Dave Crooke message dated "Sun, 20 Jun 2010 09:22:13 -0500" Date: Sun, 20 Jun 2010 11:34:41 -0400 Message-ID: <25289.1277048081@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/356 X-Sequence-Number: 39212 Dave Crooke writes: > 4. If you're trying to figure out the net size of the table, i.e. how much > free space is inside the table files for reuse by PG, then you need the > pg_stat_tuple function ... this is built in to PG 8.4, and a plug-in > activated by a script for PG 8.3, don't know if it exists in 8.1 or not. > Like SELECT COUNT(*) this requires a full table scan. I think what the OP actually wants is the number of live rows, so plain old SELECT COUNT(*) would do it. If that's too slow, a good alternative is to ANALYZE the table and then look at its pg_class.reltuples entry --- of course that will only be an approximate count. regards, tom lane