Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Created November 24, 2017 09:54
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 dineshsprabu/160e2bb3a8dea9f2409192b29d37486f to your computer and use it in GitHub Desktop.
Save dineshsprabu/160e2bb3a8dea9f2409192b29d37486f to your computer and use it in GitHub Desktop.
[Postgres] Useful Management Queries

Size of the DB

SELECT pg_size_pretty(pg_database_size('postgres'));

Size of the table with indexes

select pg_size_pretty(pg_total_relation_size('tablename'));

Size of the index

select pg_size_pretty(pg_total_relation_size('indexname'));

List biggest relations on the DB with size

SELECT 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 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment