Tags

Sometimes we want to know the current size of a certain schema in our Database. For  that create the following function.

CREATE OR REPLACE FUNCTION pg_schema_getsize(text) returns bigint AS $$
SELECT sum(pg_relation_size(schemaname || ‘.’ || tablename))::bigint FROM pg_tables WHERE schemaname = $1
$$ LANGUAGE sql;

To execute this:
select pg_size_pretty(pg_schema_getsize('backup_tables'));

pg_size_pretty
—————-
36 GB
(1 row)

Advertisements