12 November,2019 by Rambler
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') );
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |