Postgres DB Size Command
You can enter the following psql meta-command to get some details about a specified database, including its size:
\l+ <database_name>
And to get sizes of all databases (that you can connect to):
\l+
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_sizefrom pg_database t1order 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 SizeSELECT pg_size_pretty(pg_database_size('Database Name'));-- Table SizeSELECT pg_size_pretty(pg_relation_size('table_name'));