DatabaseMeter

PostgreSQL Learn

How to check PostgreSQL database size

Use PostgreSQL's built-in size functions to inspect the current database and find large relations without selecting application row contents. Then interpret the result without confusing logical database size with provider disk usage.

What PostgreSQL database size means

pg_database_size reports the total disk space used by one PostgreSQL database. It is a logical PostgreSQL measurement: a provider's disk, storage, or billing number can also include write-ahead logs, system files, backups, retained history, or provisioned headroom.

The measurement matters because a current footprint is the starting point for capacity planning. Repeated observations made with the same query can reveal a growth trend; one observation cannot.

Check the current database

This read-only query returns raw bytes for calculations and a formatted value for display.

SELECT
  current_database() AS database_name,
  pg_database_size(current_database()) AS size_bytes,
  pg_size_pretty(pg_database_size(current_database())) AS size_pretty;

Find the largest tables and materialized views

This bounded query separates table storage from attached indexes. It excludes PostgreSQL system and TOAST schemas from the ranked list, while pg_table_size still includes a table's own TOAST storage.

SELECT
  n.nspname AS schema_name,
  c.relname AS relation_name,
  CASE c.relkind
    WHEN 'r' THEN 'table'
    WHEN 'm' THEN 'materialized view'
  END AS relation_kind,
  pg_table_size(c.oid) AS table_bytes,
  pg_indexes_size(c.oid) AS index_bytes,
  pg_total_relation_size(c.oid) AS total_bytes
FROM pg_class AS c
JOIN pg_namespace AS n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'm')
  AND n.nspname NOT IN ('pg_catalog', 'information_schema')
  AND n.nspname !~ '^pg_toast'
ORDER BY total_bytes DESC
LIMIT 25;

Interpret the size functions

What PostgreSQL size functions measure
FunctionWhat it reports
pg_database_sizeTotal disk space used by the named database.
pg_table_sizeA table or materialized view excluding indexes, but including TOAST data and auxiliary forks such as the free-space and visibility maps.
pg_indexes_sizeTotal disk space used by indexes attached to a table or materialized view.
pg_total_relation_sizeThe table size plus all attached indexes.
pg_relation_sizeOne relation fork; by default, the main data fork. It is narrower than pg_table_size.

Safe inspection and useful comparisons

  • Connect to the exact database you intend to measure; current_database() confirms its name.
  • Keep discovery queries read-only, bounded with LIMIT, and filtered away from system schemas.
  • Store raw bytes and a capture timestamp if you want to calculate growth. Formatted strings are for display, not arithmetic.
  • Compare observations made with the same query, database, units, and an understood time interval.
  • Expect a busy database to change while the query runs; size calls are observations, not a transactionally frozen storage inventory.

Common misleading interpretations

PostgreSQL database size interpretation guardrails
ObservationWhat it does not prove
The database is 80 GBThat the provider bills exactly 80 GB of disk or storage.
The database grew since yesterdayThat the same pace will continue, or which workload caused it.
Rows were deletedThat relation files or provider disk usage will immediately shrink.
One relation has a large total_bytes valueThat row data alone is large; indexes and TOAST can be substantial contributors.
A partitioned parent looks smallThat its child partitions are small; measure the partition relations as well.

When DatabaseMeter can help

The PostgreSQL health check can analyze a bounded snapshot of database, table, and index footprint. A connected database can collect supported size measurements over time, making direction and change more useful than a single number. DatabaseMeter reads statistics and catalog measurements; these size checks do not select application row contents.

Use the database growth calculator when you already have two dated byte observations and want a transparent pace and threshold projection.

Definitions and sources

Provider and PostgreSQL statements last reviewed August 29, 2026. Pricing consoles and invoices remain authoritative.