Find empty tables in PostgreSQL database

This query returns a list of all tables with no rows.

Query

select n.nspname as table_schema,
       c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'r'
      and n.nspname not in ('information_schema','pg_catalog')
      and c.reltuples = 0
order by table_schema,
         table_name;

Columns

  • table_schema - table's schema name
  • table_name - table name

Rows

  • One row represents one table
  • Scope of rows: all tables without any rows
  • Ordered by schema and table name

Sample results

Empty tables in our pagila repository: