Contents
pg_total_relation_size()
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.
Usage
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.
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
- PostgreSQL 8.1
- added (commit 358a897f)
Examples
Basic usage example for pg_total_relation_size()
:
postgres=# SELECT pg_size_pretty(pg_total_relation_size('object_property')); pg_size_pretty ---------------- 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'), pg_indexes_size('object_property'), pg_total_relation_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)
References
- PostgreSQL documentation: Database Object Size Functions