Postgres DB Size Command

后端 未结 10 558
孤独总比滥情好
孤独总比滥情好 2021-01-29 17:09

What is the command to find the size of all the databases?

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

         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 18:05

    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.

提交回复
热议问题