Check table and index size in PostgreSQL
Use PostgreSQL’s size functions to measure table and index disk use in the current database. This query sorts tables by total bytes, largest first:
SELECT schemaname, relname AS table_name, pg_size_pretty(pg_table_size(relid)) AS data_size, pg_size_pretty(pg_indexes_size(relid)) AS index_size, pg_size_pretty(pg_total_relation_size(relid)) AS total_size, n_live_tup AS estimated_rowsFROM pg_stat_user_tablesORDER BY pg_total_relation_size(relid) DESC;| Result | Meaning |
|---|---|
data_size |
Table storage, including auxiliary files and out-of-line values, excluding its indexes |
index_size |
Combined size of the table’s indexes |
total_size |
Table storage plus indexes |
estimated_rows |
Estimated live rows, rather than an exact count |
A partitioned parent’s size does not automatically sum its child partitions. These are occupied disk sizes, not an estimate of space that maintenance will release.
Check table and index size in PostgreSQL with TableAI
Section titled “Check table and index size in PostgreSQL with TableAI”- Open Admin › Storage.
- Compare the Data, Index, and Total columns.
- Inspect the row estimate alongside the sizes.

For the entire database, run:
SELECT pg_size_pretty(pg_database_size(current_database())) AS database_size;Other database objects occupy space too, so this value can exceed the sum of the table list. See PostgreSQL’s size function reference.
Required privileges
Section titled “Required privileges”These checks need no extension.
Your role needs access to the relevant statistics and functions.
pg_database_size requires CONNECT on the database or suitable statistics privileges.
For a permission failure, see Admin data unavailable.