Find PostgreSQL database size using SQL ‘Select’

This article will show you a very simple way to find the size of a PostgreSQL database using a SQL SELECT statement. This will work on PostgreSQL version 8.3.3, but should work on older versions as well.


SELECT pg_database.datname,pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database where datname='database_name';

Sample Result

datname | size
database_name | 15 MB
(1 row)

The result shows the name of the database, as well as the size which in this case is 15 MB

Please post your comments/suggestions!