Skip to content

Instantly share code, notes, and snippets.

@aks
Created March 17, 2018 06:12
Show Gist options
  • Select an option

  • Save aks/70ac2d06d37f836d6053e40778bbbf72 to your computer and use it in GitHub Desktop.

Select an option

Save aks/70ac2d06d37f836d6053e40778bbbf72 to your computer and use it in GitHub Desktop.
-- quickly select the estimated row counts, using reltuples, across all tables
-- sort the results by descending size, and table names alphabetically
--
-- This relies on the table having been recently analyzed.
SELECT relname as "Table"
, to_char(reltuples::bigint, '9,999,999,999,999') AS "~Rows"
FROM pg_class
WHERE relname NOT LIKE 'pg%'
AND relkind = 'r'
ORDER BY 2 DESC, 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment