Files
DBAdmin/inbox/DataBase/PostgreSQL/object_management/size_objects..sql
T
2026-05-18 06:40:19 +00:00

22 lines
892 B
SQL

Below queries can be used to get schema wise size in postgres db
postgres=# select schemaname,pg_size_pretty(sum(pg_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename)))::bigint) as schema_size FROM pg_tables group by schemaname;
schemaname | pg_size_pretty
--------------------+----------------
raj | 8192 bytes
public | 3651 MB
pg_catalog | 2936 kB
information_schema | 96 kB
(4 rows)
postgres=# SELECT schemaname,
pg_size_pretty(sum(table_size)::bigint) as schema_size,
(sum(table_size) / pg_database_size(current_database())) * 100 as percentage_of_total_db
FROM (
SELECT pg_catalog.pg_namespace.nspname as schemaname,
pg_relation_size(pg_catalog.pg_class.oid) as table_size
FROM pg_catalog.pg_class
JOIN pg_catalog.pg_namespace ON relnamespace = pg_catalog.pg_namespace.oid
) t
GROUP BY schemaname
ORDER BY schemaname;