12

A Postgres tablespace is cluster-wide.
Therefore, how do I calculate how much space is allocated by each database in Postgres tablespaces?

1 Answer 1

20

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:

1
  • 2
    One could very usefully combine this with a SELECT on the system tables: SELECT spcname, pg_size_pretty(pg_tablespace_size(spcname)) FROM pg_tablespace; and SELECT datname, pg_size_pretty(pg_database_size(datname)) FROM pg_database;.
    – jpmc26
    Commented May 27, 2014 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.