snippetsqlMajor
How to get actually allocated tablespace sizes?
Viewed 0 times
tablespacesizesgetactuallyhowallocated
Problem
A Postgres tablespace is cluster-wide.
Therefore, how do I calculate how much space is allocated by each database in Postgres tablespaces?
Therefore, how do I calculate how much space is allocated by each database in Postgres tablespaces?
Solution
To get the disk space occupied by a database (nicely formatted):
Disk space occupied by a tablespace:
Find out more about database object size functions in the manual:
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:
Code Snippets
SELECT pg_size_pretty(pg_database_size('mydb'));SELECT pg_size_pretty(pg_tablespace_size('mytblspace'));Context
StackExchange Database Administrators Q#14623, answer score: 20
Revisions (0)
No revisions yet.