1

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?

1
  • A typo. SELECT pg_size_pretty(pg_tablespace_size('poolData')), pg_size_pretty(pg_tablespace_size ('pool')); Commented Nov 23, 2023 at 11:56

1 Answer 1

1

Function pg_tablespace_size() returns type bigint, so you can add them with a regular +.

SELECT pg_size_pretty( pg_tablespace_size('poolData')
                      +pg_tablespace_size ('pool')    );

You can also sum() sizes of tablespaces you're interested in, fetching them from pg_tablespace.

select pg_size_pretty(sum(spcname)) from pg_tablespace
where spcname in ('poolData','pool');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.