Skip to content

Instantly share code, notes, and snippets.

@schwartzmx
Created February 22, 2021 18:57
Show Gist options
  • Save schwartzmx/3777a1c73d350e1cd5825246e79a16b8 to your computer and use it in GitHub Desktop.
Save schwartzmx/3777a1c73d350e1cd5825246e79a16b8 to your computer and use it in GitHub Desktop.
SELECT c.relname AS "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'm' THEN 'materialized view' ELSE 'view' END AS "Engine",
pg_relation_size(c.oid) AS "Data_length",
pg_total_relation_size(c.oid) - pg_relation_size(c.oid) AS "Index_length",
obj_description(c.oid, 'pg_class') AS "Comment",
CASE WHEN c.relhasoids THEN 'oid' ELSE '' END AS "Oid",
c.reltuples as "Rows",
n.nspname
FROM pg_class c
JOIN pg_namespace n ON(n.nspname = current_schema() AND n.oid = c.relnamespace)
WHERE relkind IN ('r', 'm', 'v', 'f', 'p')
ORDER BY relname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment