Show the disk size of a table

Read-only
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Reports the total disk space used by a table including its indexes and TOAST data, so you can identify which tables consume the most storage.

postgresqlsizestorageinspect

Parameters

Name of the table to measure.

Commands

Display the total on-disk size of the table and its indexes

psql -c "SELECT pg_size_pretty(pg_total_relation_size('<table_name>')) AS total_size;"

Verification

psql -c "SELECT pg_size_pretty(pg_total_relation_size('<table_name>'));"

A human-readable size string like "128 MB" is printed.

Undo

Not undoable

This recipe only reads storage metadata and changes nothing.

Pitfalls

  • The table must exist and be in the search path; use schema-qualified names when needed.
  • The reported size includes dead tuples not yet vacuumed; run VACUUM first for an accurate live-tuple count.
  • Very large tables with many partitions report the size of the parent relation only; sum children separately.

Related