I know how to check the size of indexes and tables in Postgres (I'm using version 9.4):
SELECT
relname AS objectname,
relkind AS objecttype,
reltuples AS "#entries", pg_size_pretty(relpages::bigint*8*1024) AS size
FROM pg_class
WHERE relpages >= 8
ORDER BY relpages DESC;
But this doesn't show materialized views. How can I check how much disk space they are taking up?
Best Answer
This is assuming that materialized views have
relpages >= 8
inpg_class
, which doesn't have to be the case. It can actually be empty - not populated yet, indicated bypg_class.relispopulated = FALSE
. The corresponding disk file has a zero size in this case.Try instead:
Where the available types are:
Use one of the database object size functions rather than building your own. Be aware that the "size of a table" can be defined in different ways. Details: