calculating table sizes + total in one query - Mailing list pgsql-novice

From Marcin Krol
Subject calculating table sizes + total in one query
Date
Msg-id 49119A9D.7020102@gmail.com
Whole thread Raw
List pgsql-novice
Hello everyone,

Some novices may find it useful:

How to calculate disk space occupied by each of top 10 biggest tables:

SELECT relpages * 8192 AS size_in_bytes, relname FROM pg_class WHERE
relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')
ORDER BY size_in_bytes DESC LIMIT 10;

How to calculate total disk space occupied by all tables:

SELECT SUM(sizes.size_in_bytes) FROM (SELECT relpages * 8192 AS
size_in_bytes, relname FROM pg_class WHERE relnamespace = (SELECT oid
FROM pg_namespace WHERE nspname = 'public')) AS sizes;

I have two questions:

1. Is it possible to do the equivalent calculations with indexes? If so,
how?

2. Is it possible to display both top 10 tables and the total size of


Regards,
Marcin Krol

pgsql-novice by date:

Previous
From: Marcin Krol
Date:
Subject: viewing currently executing query
Next
From: Marcin Krol
Date:
Subject: VACUUM FULL