> ## Content Index
> Fetch the complete content index at: https://www.bagz.fr/llms.txt
> Use this file to discover other available public pages before exploring further.

# Find PostgreSQL database size
- URL: https://www.bagz.fr/find-postgresql-database-size/
- Published: 2014-05-03T17:10:25.000Z
- Updated: 2014-05-03T17:10:25.000Z
- Author: bgazui
- Tags: Database, #Migrated-1790668826633, #wp, #wp-post, #Import 2026-09-29 08:00

PostgreSQL is an object-relational database management system (ORDBMS). It's a free and open-source tool available under BSD licence.

Thanks to some built-in functions, you can get several information regarding database and/or table size. You will find below the main and most used examples.

### Database size (in octal)

dbpg-# SELECT pg\_database\_size(‘db\_1’);  
pg\_database\_size  
\----------------  
342733824  
(1 line)

### Database size (in human understandable format)

dbpg-# SELECT pg\_size\_pretty(pg\_database\_size(‘db\_1’));  
pg\_size\_pretty  
\--------------  
327 MB  
(1 line)

### All databases size

dbpg-# SELECT pg\_database.datname, pg\_size\_pretty(pg\_database\_size(pg\_database.datname)) AS size FROM pg\_database;  
datname | size  
\---------+-----  
postgres | 3537 kB  
db\_1 | 327 MB  
db\_2 | 4732 kB  
db\_3 | 29 MB  
db\_4 | 168 MB  
temp0 | 3928 kB  
(6 lines)

### Table size (excluding indexes and some auxiliary data)

dbpg-# SELECT pg\_size\_pretty(pg\_relation\_size(‘users’));  
pg\_size\_pretty  
\--------------  
64 kB  
(1 line)

### Table size (including all data)

dbpg-# SELECT pg\_size\_pretty(pg\_total\_relation\_size(‘users’));  
pg\_size\_pretty  
\--------------  
152 kB  
(1 line)

### Find the largest table in database

dbpg-# SELECT relname, relpages FROM pg\_class ORDER BY relpages DESC limit 1;  
relname | relpages  
\--------+---------  
db\_1 | 8732  
(1 line)

 For the full documentation, please visit <http://www.postgresql.org/>