Postgres Table Sizes

Sometimes it’s handy to know the tables in your DB that are taking up the most space. Here’s a quick query that returns the table names and pages used in descending order:


SELECT table_name, relpages
FROM information_schema.TABLES
INNER JOIN pg_class
ON relname=table_name
WHERE table_schema='public'
ORDER BY relpages DESC

 

The reason for the join on the information schema is to limit the results to just the tables you created. If you just use pg_class, then you also get the sizes of indexes and views including the postgres owned objects.

Leave a Comment