How to Check Database and Table Size in PostgreSQL

This tutorial will help you to check out database and table size in PostgreSQL server.

Login to your server using command line and connect to PostgreSQL server.

Now you can use following commands to check sizes of databases and tables in PostgreSQL.

To check Database Size in PostgreSQL execute following command from PostgreSQL command prompt:

postgres=# SELECT pg_size_pretty(pg_database_size('mydb'));

To check table size in PostgreSQL execute following command from PostgreSQL command prompt.

postgres=# \connect mydb;

mydb=# SELECT pg_size_pretty( pg_total_relation_size('mytbl'));

Done!!