In Postgres you could be managing many databases on a Cluster.
In some cases you may need to query the size all of these databases.
You can query the size of a database or all databases in the cluster with the help of the following scripts.
Find the Size of a Database in PostgreSQL
1 2 3 |
SELECT pg_database.datname as "databasename", pg_database_size(pg_database.datname)/1024/1024/1024 AS sizegb FROM pg_database ORDER by pg_database_size(pg_database.datname) DESC; |
Find the Size of all Databases in PostgreSQL
1 2 3 4 5 |
SELECT pg_database.datname as "databasename", pg_database_size(pg_database.datname)/1024/1024/1024 AS sizegb FROM pg_database WHERE pg_database.datname='Test' ORDER by pg_database_size(pg_database.datname) DESC; |
If you want to list the the size of tables in postgresql, you should read the following article.
“How To Find the Size of Tables and Indexes in PostgreSQL”