Skip to content

Instantly share code, notes, and snippets.

@dadhi
Last active April 11, 2024 13:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadhi/25f0a3e3d11175e073bc280aa770e9e4 to your computer and use it in GitHub Desktop.
Save dadhi/25f0a3e3d11175e073bc280aa770e9e4 to your computer and use it in GitHub Desktop.
Find disk size of Postgres materialized view
/*
https://dba.stackexchange.com/questions/96534/postgres-check-disk-space-taken-by-materialized-view?newreg=6b1d58604fce4a1fbe3033ddbb52d7ca
relkind:
r = ordinary table,
i = index,
S = sequence,
v = view,
m = materialized view,
c = composite type,
t = TOAST table,
f = foreign table
*/
SELECT relname AS objectname
, relkind AS objecttype
, reltuples AS entries
, pg_size_pretty(pg_table_size(oid)) AS size -- depending - see below
FROM pg_class
WHERE relkind IN ('m')
ORDER BY pg_table_size(oid) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment