← Free tools

PostgreSQL table size checker

Find the largest tables in your PostgreSQL database. This read-only query ranks tables by disk footprint, includes indexes and TOAST, and rolls local partitions up to their parent.

No sign-up. Your report stays in this browser.

Run the table size query

Run in your SQL client on PostgreSQL 12 or newer. It returns one JSON cell named storage_report for the largest 50 tables.

WITH local_tables AS MATERIALIZED (
  SELECT CASE WHEN c.relispartition THEN pg_catalog.pg_partition_root(c.oid)::oid
              ELSE c.oid END AS table_oid,
         pg_catalog.pg_table_size(c.oid) AS data_bytes,
         pg_catalog.pg_indexes_size(c.oid) AS index_bytes
  FROM pg_catalog.pg_class AS c
  JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
  WHERE c.relkind = 'r'
    AND c.relpersistence <> 't'
    AND n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema')
), ranked AS (
  SELECT n.nspname AS schema_name, c.relname AS table_name,
         sum(t.data_bytes) AS data_bytes, sum(t.index_bytes) AS index_bytes,
         sum(t.data_bytes + t.index_bytes) AS total_bytes
  FROM local_tables AS t
  JOIN pg_catalog.pg_class AS c ON c.oid = t.table_oid
  JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
  GROUP BY n.nspname, c.relname
  ORDER BY total_bytes DESC, schema_name, table_name
  LIMIT 50
)
SELECT coalesce(jsonb_agg(jsonb_build_object(
    'schema_name', schema_name, 'table_name', table_name,
    'data_bytes', data_bytes::text, 'index_bytes', index_bytes::text
  ) ORDER BY total_bytes DESC, schema_name, table_name), '[]'::jsonb)
  AS storage_report
FROM ranked;

Open your storage report

Sample table sizes

Example results in descending disk size. Most of this sample footprint is in orders.

TableDataIndexesTotalCompression
public.orders80 GiB20 GiB100 GiBEstimate savings
audit.events50 GiB10 GiB60 GiBEstimate savings
public.customers8 GiB4 GiB12 GiBEstimate savings

Read the storage breakdown

Total is data plus attached indexes. Data includes the main table, TOAST storage and auxiliary space maps. The query reads catalogs and relation sizes in the current database. It skips system and temporary tables, views, materialized views and foreign tables.

When opening a table in the compression calculator, adjust the older storage share to match your retention cutoff. The table size comes from this report and the 75% share starts as an example. Tables from 0.01 to 1,000,000 GiB can be opened directly.

PostgreSQL size functions documentation

Continue with a related task

Questions

How do I find the largest tables in PostgreSQL?

Use pg_total_relation_size for an individual table. To rank many tables, add pg_table_size and pg_indexes_size for each table, sum partition sizes under their parent, and sort by total bytes. The query above does this for the largest 50 logical tables in the current database.

Does PostgreSQL table size include indexes and TOAST?

pg_total_relation_size includes indexes and TOAST. This report splits that total into data and indexes. Data includes the TOAST table, free space and visibility maps. Indexes are the indexes attached directly to the table.

How do I check the size of a partitioned table?

Sum the sizes of the local leaf partitions. A partitioned parent has no heap of its own. The report groups local leaves under the root, including multi-level partitions, and skips foreign partitions because their storage is remote.

Does this show how much disk I can reclaim?

The query measures allocated disk space, including space PostgreSQL may already be able to reuse. It does not measure bloat or tell you how much space belongs to older rows. If the table contains cold history, take its total into the compression calculator and enter the estimated share of older data.