12 November,2019 by
Jack Vamvas
Question : How can I calculate the size of a PostgreSQL database using psql?I want to use the command line and execute a sql statement for various checks?
Answer: An easy way to derive the Postgresql database size is to use the pg_database_size() function. The pg_database_size() reads the database name and returns the database size in bytes.
For example : SELECT pg_database_size(‘my_db_name’)
This returns in bytes – which unless you enjoy calculating byte sizes – there is another function you can use which will make these numbers human readable – pg_size_pretty()
Combining these two functions will return the database size in a a human readable method –
SELECT pg_size_pretty( pg_database_size(‘my_db_name’) );
Author: Jack Vamvas
Leave a Reply