Nazarii Gudzovatyi

Errors should never pass silently.

Postgres: Find the Biggest Tables

Usefull query to find 20 biggest tables in your PostgreSQL database:

SQL
1
2
3
4
5
6
7
SELECT nspname || '.' || relname AS "relation",
    pg_size_pretty(pg_relation_size(C.oid)) AS "size"
  FROM pg_class C
  LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
  WHERE nspname NOT IN ('pg_catalog', 'information_schema')
  ORDER BY pg_relation_size(C.oid) DESC
  LIMIT 20;

Comments