Skip to content

Instantly share code, notes, and snippets.

@camallen
Created December 6, 2018 11:03
Show Gist options
  • Save camallen/8d775d57801dfb3339a57d38e10cddcf to your computer and use it in GitHub Desktop.
Save camallen/8d775d57801dfb3339a57d38e10cddcf to your computer and use it in GitHub Desktop.
find large toast relation pg
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;
select t1.oid, t1.relname, t1.relkind, t2.relkind, t2.relpages, t2.reltuples
from pg_class t1
inner join pg_class t2
on t1.reltoastrelid = t2.oid
where t1.relkind = 'r'
and t2.relkind = 't'
order by reltuples DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment