In this article, we will see how to find list of databases and their sizes in PostgreSQL.
Find the list of databases in PostgreSQL Server.
We can find the databases by using:
1. with meta-command
2. By querying against pg_database table.
Using meta-command:
\l or \list meta-command is used to find the PostgreSQL databases names.
By querying against pg_database table
select datname from pg_database;
Find database sizes:
We can find the databases sizes by using:
1. with meta-command
2. By querying against pg_database table.
Using meta-command:
\l
Find Individual Database size:
Find database size using meta-command:
\l+ r2schools
Find all database sizes using meta-command:
\l+
By querying against pg_database table
1. Find individual database size.
select pg_size_pretty(pg_database_size('r2schools'));
2. Find all databases size in PostgreSQL server.
select datname AS database_name, pg_size_pretty(pg_database_size(datname)) as db_size from pg_database order by pg_database_size(datname) desc;