How can I query the size of my Postgres database?
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)