How can I query the size of my Postgres database?

Issue

I would like to write a SQL query to check the overall size my data in the Postgres database.

Resolution

There are several handy Postgres functions that you can use to query and format the database size:

pg_size_pretty: Converts a size in bytes expressed as a numeric value into a human-readable format with size units.
pg_database_size: Disk space used by the database with the specified OID.
current_database: Name of current database

Put these together and you can write a query like so:

sushi_db::DATABASE=> SELECT pg_size_pretty(pg_database_size(current_database())) as size;
 size  
-------
 13 MB
(1 row)

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support
Terms of Service Privacy Cookies © 2018 Salesforce.com