How to Check Table Size in PostgreSQL

Galaxy Glossary

How do I check the size of a table in PostgreSQL?

Use built-in size functions to report the exact on-disk bytes a specific table (and its indexes) occupy.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Description

Table of Contents

Why should I monitor table size?

Table growth signals rising storage costs, longer backup times, and slower queries. Knowing size trends lets you archive old data, add partitions, or increase hardware before performance drops.

Which functions reveal table size?

Use pg_table_size() for the heap only, pg_indexes_size() for indexes, and pg_total_relation_size() for heap + toast + indexes. Wrap them in pg_size_pretty() for human-readable output.

How do I check one table’s size quickly?

Select pg_size_pretty(pg_total_relation_size('"Orders"')). This returns a formatted string such as 256 MB.

How can I list the largest tables?

Order every table by pg_total_relation_size descending. This highlights storage hotspots that need pruning or indexing tweaks.

Best practice: automate size audits

Schedule a nightly query in cron or pgAgent to write current sizes to a metrics table. Plot results in Grafana to catch sudden spikes.

What is the exact syntax?

See the syntax and ecommerce example below.

Why How to Check Table Size in PostgreSQL is important

How to Check Table Size in PostgreSQL Example Usage


-- How large is the "OrderItems" table, including indexes?
SELECT pg_size_pretty(pg_total_relation_size('"OrderItems"')) AS orderitems_size;

-- Result
-- orderitems_size
-- 74 MB

How to Check Table Size in PostgreSQL Syntax


-- Report full disk usage for one table
SELECT pg_size_pretty(pg_total_relation_size('<table_name>')) AS full_size;

-- Show heap, index, and total sizes side by side
SELECT 
    pg_size_pretty(pg_table_size('<table_name>'))  AS data_only,
    pg_size_pretty(pg_indexes_size('<table_name>')) AS indexes,
    pg_size_pretty(pg_total_relation_size('<table_name>')) AS total
;

-- Ecommerce example: find top 5 largest tables
SELECT 
    relname                                        AS table,
    pg_size_pretty(pg_total_relation_size(relid))  AS total_size
FROM pg_catalog.pg_statio_user_tables 
ORDER BY pg_total_relation_size(relid) DESC 
LIMIT 5;

Common Mistakes

Frequently Asked Questions (FAQs)

Does pg_total_relation_size lock the table?

No. It reads catalog statistics and system files, so it doesn’t block reads or writes.

Should I include TOAST tables?

Yes. pg_total_relation_size automatically adds TOAST and index sizes, giving a complete picture.

How can I watch growth over time?

Store daily sizes in a monitoring table and graph them. Sudden jumps often reveal runaway logs or missing partitions.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.