Skip to content

Instantly share code, notes, and snippets.

@konjoot
Last active November 27, 2018 14:35
Show Gist options
  • Save konjoot/ad7b7b55fc5a4a8a89b2370ae989bea8 to your computer and use it in GitHub Desktop.
Save konjoot/ad7b7b55fc5a4a8a89b2370ae989bea8 to your computer and use it in GitHub Desktop.
List tables sorted by size with rows count by schema (PostgreSQL only)
SELECT table_name,
pg_relation_size(quote_ident(table_name)) AS size,
n_live_tup AS rows
FROM information_schema.tables AS it
JOIN pg_stat_user_tables AS ut
ON it.table_name = ut.relname
AND it.table_schema = ut.schemaname
WHERE table_schema = 'public'
ORDER BY 2 DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment