May 17, 2026, 11:40 PM
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user