A Postgres tablespace is cluster-wide.
Therefore, how do I calculate how much space is allocated by each database in Postgres tablespaces?
1 Answer
To get the disk space occupied by a database (nicely formatted):
SELECT pg_size_pretty(pg_database_size('mydb'));
Disk space occupied by a tablespace:
SELECT pg_size_pretty(pg_tablespace_size('mytblspace'));
Find out more about database object size functions in the manual:
-
2One could very usefully combine this with a
SELECT
on the system tables:SELECT spcname, pg_size_pretty(pg_tablespace_size(spcname)) FROM pg_tablespace;
andSELECT datname, pg_size_pretty(pg_database_size(datname)) FROM pg_database;
.– jpmc26Commented May 27, 2014 at 20:59