pg_indexes_size() is a system function determining the total on-disk size of a table's indexes.
pg_indexes_size() was added in PostgreSQL 9.0.
The caller does not require any permissions on the table to determine the size of its indexes. An
ACCESS EXCLUSIVE lock on the table will however cause the function to stall until the lock is released.
The source code for
pg_indexes_size() is contained in src/backend/utils/adt/dbsize.c; the main work is carried out by
Basic usage example for
postgres=# SELECT pg_size_pretty(pg_indexes_size('object_property')); pg_size_pretty ---------------- 19 MB (1 row)
Note that as of PostgreSQL 14,
pg_indexes_size() will accept the name of any valid relation, not just tables, in which case it will always report an index size of
postgres=# SELECT pg_indexes_size('object_property_pkey'); pg_indexes_size ----------------- 0 (1 row)
Attempting to retrieve the total index size of a non-existent relation:
postgres=# SELECT pg_indexes_size('foo'); ERROR: relation "foo" does not exist LINE 1: SELECT pg_indexes_size('foo');;