How do I find out the size of a PostgreSQL database?

Question:

There is a PostgreSQL base , a postgres user. How to get the size of the database with one command, without using scripts?

Answer:

In human form, the size of the database will be shown by the wrapper pg_size_pretty

SELECT pg_size_pretty( pg_database_size( 'sample_db' ) );

 pg_size_pretty 
----------------
36 GB

In the same way, you can see the size of the table (with indexes)

SELECT pg_size_pretty( pg_total_relation_size( 'table' ) );

 pg_size_pretty 
----------------
 6341 MB

If you need without indexes, then the query is different:

# SELECT pg_size_pretty( pg_relation_size( 'table' ) );

 pg_size_pretty 
----------------
 1341 MB
Scroll to Top