A function for determining the total size of a relation

pg_total_relation_size() is a system function determining the total on-disk size of a relation, including data and any indexes.

pg_total_relation_size() was added in PostgreSQL 8.1.


pg_total_relation_size ( regclass ) → bigint

pg_total_relation_size() returns the sum of the values that pg_table_size() and pg_indexes_size() would return for the relation.

An ERROR is raised if a non-existent relation is specified by name.

NULL is returned if an OID is provided which does not map to an existing relation.

The caller does not require any permissions on the table to determine its size. An ACCESS EXCLUSIVE lock on the table will however cause the function to stall until the lock is released.

Change history


Basic usage example for pg_total_relation_size():

postgres=# SELECT pg_size_pretty(pg_total_relation_size('object_property'));
 492 MB
(1 row)

pg_total_relation_size()returns the same value as the sum of values returned by pg_table_size() and pg_indexes_size():

appdb=> WITH sizes AS (
          SELECT pg_table_size('object_property'),
        SELECT pg_total_relation_size, pg_table_size + pg_indexes_size
          FROM sizes;
 pg_total_relation_size | ?column?
              515989504 | 515989504
(1 row)


System function

See also

pg_table_size(), pg_indexes_size(), pg_relation_size()