Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Mar 8 '12 at 6:47

This question came from our site for professional and enthusiast programmers.

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:

share|improve this answer
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 May 27 '14 at 20:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.