Last active
June 9, 2022 00:27
-
-
Save ZsBT/769e4ccc9de77e6e1dd3a4293354f7f4 to your computer and use it in GitHub Desktop.
show occupied space in a postgresql database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create view v_sizeof_dbs as | |
select datname dbname | |
,pg_size_pretty(pg_database_size(datname)) hsize | |
from pg_database | |
order by pg_database_size(datname) desc; | |
create view v_sizeof_tables as | |
SELECT table_catalog,table_schema,table_name | |
,pg_size_pretty(pg_table_size(table_schema||'.'||table_name)) table_hsize | |
FROM information_schema.tables | |
where not table_schema in ('pg_catalog','information_schema') | |
and table_type like '%TABLE%' | |
ORDER BY (pg_table_size(table_schema||'.'||table_name)) desc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment