Skip to content

Instantly share code, notes, and snippets.

@jimcavoli
Created June 17, 2018 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimcavoli/2fb0ae1349e69cc18ec5bdd7a02a8c3f to your computer and use it in GitHub Desktop.
Save jimcavoli/2fb0ae1349e69cc18ec5bdd7a02a8c3f to your computer and use it in GitHub Desktop.
Handy PostgreSQL maintenance queries
-- Lists the size of all relations in the current 'public' schema in descending order
SELECT
nspname||'.'||relname AS relation,
pg_size_pretty(pg_total_relation_size(nspname||'.'||relname)) as pretty_size,
pg_total_relation_size(nspname||'.'||relname) as raw_size
FROM
pg_class, pg_namespace
WHERE
relnamespace = pg_namespace.oid
AND
nspname = 'public'
ORDER BY
raw_size DESC
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment