O'Reilly logo

PostgreSQL 9 Administration Cookbook by Hannu Krosing, Simon Riggs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How much disk space does a table use?

How big is a table? What is the total of all the parts of a table?

How to do it...

We can find out the size of a table using the following query:

postgres=# select pg_relation_size('accounts');
pg_relation_size
------------------
				0
(1 row)

We can also find out the total size of a table including indexes and other related space using the following query:

postgres=# select pg_total_relation_size('accounts');
pg_total_relation_size
------------------------
				0
(1 row)

or we can also use a psql command as follows:

 postgres=# \dt+ accounts List of relations Schema | Name | Type | Owner | Size | Description ------------+--------------- --------+--------+---------+----------+---------------- public | pgbench_accounts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required