Postgresql check table and databse size

to check the table size of database ordery by desc:
---------------------------------------------------
select
   relname as "TABLENAME",schemaname as "SCHEMANAME",
   pg_size_pretty(pg_total_relation_size(relid)) As "SIZE",
   pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "EXTERNAL SIZE"
   from pg_catalog.pg_statio_user_tables order by pg_total_relation_size(relid) DESC;
 
To check database Size:-
SELECT
    pg_database.datname,
    pg_size_pretty(pg_database_size(pg_database.datname)) AS size
    FROM pg_database

Comments

Popular Posts