PostgreSQL table size: data, indexes and total bytes
Use pg_total_relation_size to check how much storage a PostgreSQL table takes up, including its indexes and TOAST data. Counting rows won’t give you that answer. The queries below separate the storage figures so you can see where the space goes.
Measure one table
Replace public.orders with an existing table. The regclass cast looks up that schema-qualified name.
SELECT
pg_size_pretty(pg_table_size('public.orders'::regclass)) AS table_storage,
pg_size_pretty(pg_indexes_size('public.orders'::regclass)) AS indexes,
pg_size_pretty(pg_total_relation_size('public.orders'::regclass)) AS total;
For numeric comparisons, keep the raw byte values and format only at display time. Sorting formatted strings can put sizes in an unexpected order. PostgreSQL documents these functions in its database object size reference.
Find the largest ordinary user tables
SELECT schemaname, relname,
pg_total_relation_size(relid) AS total_bytes
FROM pg_stat_user_tables
ORDER BY total_bytes DESC
LIMIT 20;
This is a useful starting inventory, not a complete storage billing report. Partitioned datasets require looking at their child relations; the parent name alone is not the aggregate size of the entire hierarchy. Database storage also differs from a provider's billable storage accounting.
Keep row counts separate
SELECT COUNT(*) FROM public.orders; counts rows visible to that query's snapshot. It can be expensive on a large table. Statistics-based row estimates are useful for orientation but are not a substitute for an exact count when reconciling an export. The statistics documentation describes the available views and estimates.
Make a useful baseline
Record the database, schema, table, collection time and raw bytes before a large import. Repeat afterwards with the same query and role. If indexes dominate growth, inspect their definitions and usage before proposing deletion. If a table grows despite stable row counts, investigate its workload and maintenance history rather than assuming the size query is wrong.
plainDB exposes table and database storage information where the engine supports it. Keep this SQL beside the UI result when you need a reproducible measurement to share with a teammate.
Continue reading
Review index definitions · Check export completeness
For the desktop workflow, compare plainDB features on Mac and Windows or download the 14-day trial.