Find largest tables in Postgres

/ Published in: SQL
Save to your folder(s)

Copy this code and paste it in your HTML
  1. SELECT nspname || '.' || relname AS "relation",
  2. pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
  3. FROM pg_class C
  4. LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
  5. WHERE nspname NOT IN ('pg_catalog', 'information_schema')
  6. AND C.relkind <> 'i'
  7. AND nspname !~ '^pg_toast'
  8. ORDER BY pg_total_relation_size(C.oid) DESC
  9. LIMIT 20;

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.