A function for determining the size of a relation's fork

pg_relation_size() is a system function for determining the on-disk size of a particular fork of a relation.

pg_relation_size() was added in PostgreSQL 8.1.


pg_relation_size ( relation regclass [, fork text ] ) → bigint

fork can be one of the following values (if not specified, defaults to main):

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

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.

Note that for most purposes it will be more convenient to use one of pg_total_relation_size() or pg_table_size().

Change history


Basic usage example for pg_relation_size():

postgres=# SELECT pg_relation_size('app.object', 'fsm');
(1 row)

Attempting to query the size of a non-existent relation:

postgres=# SELECT pg_relation_size('foo');
ERROR:  relation "foo" does not exist
LINE 1: SELECT pg_relation_size('foo');

Providing an OID which does not map to an existing relation:

postgres=# SELECT pg_relation_size(123);
(1 row)


System function

See also

pg_total_relation_size(), pg_table_size(), pg_indexes_size()