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+
Answer from Ashish on Stack Overflow Top answer 1 of 15
675
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+
2 of 15
390
You can select the names of all the databases for which you have CONNECT privileges from the "pg_database" 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 Guide
database.guide › get-the-size-of-all-databases-in-postgresql-psql
Get the Size of All Databases in PostgreSQL (psql)
When using psql with PostgreSQL, we can use the \list+ command to return information about all databases on the server.
SQL Conjuror
sqlconjuror.com › home › postgresql – get the size of all databases
PostgreSQL – Get the Size of All Databases | SQL Conjuror
November 14, 2022 - Here is a script to get the size of all your PostgreSQL databases. SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner, CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT') THEN pg_catalog.pg_size_pretty( pg_catalog.pg_database_size(d.datname) ) ELSE 'No Access' END AS SIZE FROM pg_catalog.pg_database d ORDER BY CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT') THEN pg_catalog.pg_database_size(d.datname) ELSE NULL END DESC; Cheers!
Beekeeper Studio
beekeeperstudio.io › blog › how-to-list-databases-in-postgres
How to List Databases Using the psql command line tool | Beekeeper Studio
April 21, 2024 - SELECT datname AS database_name, pg_size_pretty(pg_database_size(datname)) AS size, datallowconn AS allow_connections, datconnlimit AS connection_limit, encoding, datcollate, datctype FROM pg_catalog.pg_database; ... This query provides insights into the database’s configurations and settings. Beekeeper Studio lists all databases in a dropdown at the top of the interface, switch between databases at any time. ... In summary, list all the databases in psql using \l.
Postgresscripts
postgresscripts.com › post › list-and-organize-your-postgresql-databases-by-size-with-access-check
List PostgreSQL Databases by Size with Access Check | Postgres Scripts
April 1, 2024 - List and sort your PostgreSQL databases by size while checking access permissions. A practical SQL snippet for database administrators managing storage.
Peterbe.com
peterbe.com › plog › show-size-of-every-postgresql-database
Show size of every PostgreSQL database you have - Peterbe.com
tl;dr; SELECT pg_database.datname, pg_database_size(pg_database.datname), pg_size_pretty(pg_database_size(pg_database.datname)) FROM pg_database ORDER by 2 DESC;
Commandlinefu
commandlinefu.com › commands › view › 9792 › list-all-databases-in-postgres-and-their-bytehuman-sizes-ordering-by-byte-size-descending
List all databases in Postgres and their (byte/human) sizes, ordering by byte size descending
November 30, 2011 - psql -c \"SELECT pg_database.datname, pg_database_size(pg_database.datname), pg_size_pretty(pg_database_size(pg_database.datname)) FROM pg_database ORDER BY pg_database_size DESC;\" -d - (List all databases in Postgres and their (byte/human) sizes, ordering by byte size descending Get a listing of all of your databases in Postgres and their sizes, ordering by the largest size first.
CommandPrompt Inc.
commandprompt.com › education › how-to-get-database-size-and-table-size-in-postgresql
How to Get Database Size and Table Size in PostgreSQL — CommandPrompt Inc.
August 24, 2022 - In PostgreSQL, built-in functions like pg_database_size(), pg_relation_size(), and pg_total_relation_size() are used to get the database and table size. The pg_total_relation_size() function is used to fetch the total size of a relation including ...
Call +1-503-667-4564
Address 2950 Newmarket ST STE 101 - 231, 98226, Bellingham
Database Guide
database.guide › 2-ways-to-get-the-size-of-a-database-in-postgresql
2 Ways to Get the Size of a Database in PostgreSQL
... he PG_DATABASE_SIZE() function, you must have CONNECT privilege on the specified database (which is granted by default) or be a member of the pg_read_all_stats role. If you’re using psql, you can run the \l+ command. ... List of databases +--------+----------+----------+-------------...
Database Tutorials
dbtut.com › home › postgresql
How to Find The Size of all Databases in PostgreSQL - Database Tutorials
October 31, 2019 - 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 SELECT
DB Pro
dbpro.app › learn › postgres › guides › list-databases
PostgreSQL list databases | DB Pro
| Task | Command | |------|---------| | List all databases (psql) | \l | | List with sizes (psql) | \l+ | | List matching a pattern (psql) | \l myapp* | | List from the shell | psql -l | | List via SQL | SELECT datname FROM pg_database | | Exclude template databases | Add WHERE datistemplate = false | | Check if a database exists | SELECT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'name') | | Get database size | SELECT pg_size_pretty(pg_database_size('name')) | | Connect to a database | \c dbname |
A2 Hosting
a2hosting.com › kb › developer-corner › postgresql › determining-the-size-of-postgresql-databases-and-tables
The Best Web Hosting Services at 20x Speeds | hosting.com
Our platform offers a wide range of services that support websites and projects of all sizes. From your first visitor to your millionth, we have a plan for you. ... Trusted by over 700,000 customers to power 3,000,000+ websites! ... Tailored for creators, trusted by agencies and built to scale with enterprises.
KB Hosting
kb.hosting.com › developer corner › postgresql › determining the size of postgresql databases and tables
Determining the size of PostgreSQL databases and tables - hosting.com
3 weeks ago - You can use the psql command-line program to determine the sizes of PostgreSQL databases and tables. To do this, follow these steps: Log in to your account using SSH. At the command line, type the following command. Replace dbname with the name of the database, and username with the database username: