table disk space usage query?

Started by Nonamealmost 19 years ago2 messagesgeneral
Jump to latest
#1Noname
lawpoop@gmail.com

Hello all -

I was looking for a way to find out how much disk space each table is
using.

I stumbled upon this page ( http://www.ffnn.nl/pages/articles/linux/postgresql-tips-and-tricks.php
) which gave me a query to show the number of disk pages per object.
Given that a page is 8kb, I added these calculated columns to the
query:

SELECT relname, reltuples, relpages,
relpages * 8 AS relpagesKB,
(relpages * 8 )/1024 AS relpagesMB
FROM pg_class ORDER BY relpages DESC ;

Is this correct?

#2Dimitri Fontaine
dimitri@2ndQuadrant.fr
In reply to: Noname (#1)
Re: table disk space usage query?

Le jeudi 28 juin 2007, lawpoop@gmail.com a écrit :

Hello all -

I was looking for a way to find out how much disk space each table is
using.

As of PostgreSQL 8.1 you can use the following:
http://www.postgresql.org/docs/8.1/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE

Example query to obtain per-table on-disk size:

select tablename,
pg_size_pretty(pg_relation_size(tablename)) as size,
pg_size_pretty(pg_total_relation_size(tablename)) as total,
pg_relation_size(tablename)
from pg_tables
where schemaname = 'public' and tablename !~ '^pg_'
order by 4 desc;

Regards,
--
dim