I was poking around to see if you can come up with an estimate for free
space in a table... Not having much luck..

Best I found was the below, which is only anywhere near close on tables
that store stats on all columns -- which isn't normal.

select relname
     , relpages * 8192 as spaceused
     , relpages * (8192 - 20)
       - (reltuples * (
           coalesce((select sum(stawidth * (1 - stanullfrac))
                       from pg_statistic
                      where starelid = pg_class.oid)
                   , 0) + 23)
         ) as freespace
  from pg_class
 where relkind in ('r');

-- 
Rod Taylor <rbt@rbt.ca>

PGP Key: http://www.rbt.ca/rbtpub.asc
20 May 2003 22:45:32 -0400
Rod Taylor <rbt@rbt.ca>
Free Space?
Rod Taylor <rbt@rbt.ca> writes:
> I was poking around to see if you can come up with an estimate for free
> space in a table... Not having much luck..

contrib/pgstattuple/ might help.

			regards, tom lane

Wed, 21 May 2003 00:25:50 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Free Space? 