Skip to content

Instantly share code, notes, and snippets.

@FragLegs
Created January 17, 2020 21:38
Show Gist options
  • Save FragLegs/4c7b60c5e682923101c417a33b71e70d to your computer and use it in GitHub Desktop.
Save FragLegs/4c7b60c5e682923101c417a33b71e70d to your computer and use it in GitHub Desktop.
DB scripts

TOTAL DISK SIZE

WITH sizes AS (SELECT nspname || '.' || relname AS "relation",
    pg_total_relation_size(C.oid) AS "total_size"
  FROM pg_class C
  LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
  WHERE nspname NOT IN ('pg_catalog', 'information_schema')
    AND C.relkind <> 'i'
    AND nspname !~ '^pg_toast'
) SELECT pg_size_pretty(SUM(total_size)) FROM sizes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment