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.
text] ) →
fork can be one of the following values (if not specified, defaults to
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.
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.
Basic usage example for
postgres=# SELECT pg_relation_size('app.object', 'fsm'); pg_relation_size ------------------ 24576 (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); pg_relation_size ------------------ (1 row)