How to Get the Size of a Postgres Table

To get a Postgres table’s size, run the following SQL. Size here means how much space the table’s data takes up on disk or SSD. The size is returned in an easy-to-read form, e.g. “865 MB” or “12 kB” – whichever is the closest unit.

You can run the SQL using tools such as psql, pgAdmin or phpPgAdmin.

The SQL to get a table size is:

select pg_size_pretty(pg_relation_size('the_table'));

Replace “the_table” with the table name you want to check.

The result looks like this:

 pg_size_pretty
----------------
 804 kB

Note that the size reported by the SQL above does not include the size of the table’s indexes. To find out more about getting a table’s size, see the source article Get the Size of a Postgres Table . This article also includes useful information, such as how to get the table size as an exact number of bytes, and why PostgreSQL’s table data sizes are always a multiple of 1 KB.

Tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *