HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

How to get actually allocated tablespace sizes?

Submitted by: @import:stackexchange-dba··
0
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?

Solution

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:

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.