Postgres DB Size Command

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');

And... If in case you may not want to type a whole query... you can also type...

l+ <database_name>

and you will get some details about the database, including the size of the database.

And... To get sizes of all databases.

you can just type...

l+

You may need to go into the postgresql command prompt to query with these postgresql helper commands.

Check other postgresql helper commands by typing

?

at the postgresql command prompt.


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.


-- Database Size
SELECT pg_size_pretty(pg_database_size('Database Name'));
-- Table Size
SELECT pg_size_pretty(pg_relation_size('table_name'));
链接地址: http://www.djcxy.com/p/79062.html

上一篇: Heroku:更新数据库计划,然后删除第一个

下一篇: Postgres数据库大小命令