Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there any command to find all the databases size in Postgres?

I am able to find the size of a specific database by using following command:

select pg_database_size('databaseName');
share|improve this question
add comment

2 Answers

Database Size
SELECT pg_size_pretty(pg_database_size('Database Name'));
Table Size
SELECT pg_size_pretty( pg_relation_size('table_name'));

share|improve this answer
    
How is that answer different to Mike's? –  a_horse_with_no_name Sep 20 '13 at 6:58
add comment

You can get the names of all the databases that you can connect to from the "pg_datbase" system table. Just apply the function to the names, as below.

select t1.datname AS db_name,  
       pg_size_pretty(pg_database_size(t1.datname)) as db_size
from pg_database t1
order by pg_database_size(t1.datname) desc;

If you intend the output to be consumed by a machine instead of a human, you can cut the pg_size_pretty() function.

share|improve this answer
    
Sometimes database contains indexes also. It has some storage value. I am looking for one command that will provide size of the complete database. –  user2151087 Sep 20 '13 at 4:12
1  
@user2151087: pg_database_size() includes the sizes for indexes –  a_horse_with_no_name Sep 20 '13 at 6:00
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.