What I am trying to do is to calculate the sum of the 2 tableSpaces I have in my PostgreSQL DB.
SELECT pg_size_pretty (pg_tablespace_size ('pg_default') );
with this query I am able to find the used space but when I modified it to find the details of both the tablespaces by using below query
SELECT pg_size_pretty ( pg_tablespace_size ('poolData')
,pg_tablespace_size ('pool') );
but it didn’t gave any output. Is there any way to find both in a single query, so that I can calculate the sum of tablespaces?
2
Answers
Function
pg_tablespace_size()
returns typebigint
, so you can add them with a regular+
.You can also
sum()
sizes of tablespaces you’re interested in, fetching them frompg_tablespace
.To be able to find the sum of tablespaces in postgresql in this scenario i would recommend that you use the following query :
The query above retrieves the size of each tablespace individually and then calculates the sum of the sizes.