pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dan Harris <fbsd@drivefaster.net>
To: pgsql-admin@postgresql.org
Subject: Re: finding fragmented tables
Date: Wed, 09 May 2007 22:15:51 -0600
Message-ID: <46429C77.5090302@drivefaster.net> (raw)
In-Reply-To: <A551B98FF8BEE54DAB4B5A1600F7571A02F5362C@mb01.hq.perpetual.int>
References: <A551B98FF8BEE54DAB4B5A1600F7571A02F5362C@mb01.hq.perpetual.int>

Carin Westblom wrote:
> How can I easily find specific tables and/or databases with a lot of 
> space that may be reclaimed w a vacuum full?
> 

I picked up this tip on the list a while ago:

SELECT pg_namespace.nspname, pg_class.relname, pg_class.reltuples, 
pg_class.relpages, rowwidths.avgwidth, ceil(pg_class.reltuples * 
rowwidths.avgwidth::double precision / 
current_setting('block_size'::text)::double precision) AS expectedpages, 
pg_class.relpages::double precision / ceil(pg_class.reltuples * 
rowwidths.avgwidth::double precision / 
current_setting('block_size'::text)::double precision) AS bloat, 
ceil((pg_class.relpages::double precision * 
current_setting('block_size'::text)::double precision - ceil(pg_class.reltuples 
* rowwidths.avgwidth::double precision)) / 1024::double precision) AS wastedspace
    FROM ( SELECT pg_statistic.starelid, sum(pg_statistic.stawidth) AS avgwidth
            FROM pg_statistic
           GROUP BY pg_statistic.starelid) rowwidths
    JOIN pg_class ON rowwidths.starelid = pg_class.oid
    JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
   WHERE pg_class.relpages > 1;


then do:

select * from relbloat order by wastedspace desc;



view thread (3+ messages)  latest in thread

Message-ID: <46429C77.5090302@drivefaster.net>
Permalink:  ../46429C77.5090302@drivefaster.net/
Also on:    postgresql.org/message-id/46429C77.5090302@drivefaster.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: fbsd@drivefaster.net
  Subject: Re: finding fragmented tables
  In-Reply-To: <46429C77.5090302@drivefaster.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox