/** * Creates a function which returns the size of a schema. * * @author: "Stefanie Janine Stölting" * @license: PostgreSQL https://opensource.org/licenses/postgresql */ CREATE OR REPLACE FUNCTION pg_schema_size(text) RETURNS BIGINT AS $$ SELECT COALESCE(SUM(pg_total_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename)))::BIGINT, 0) AS schema_size FROM pg_tables WHERE schemaname = $1 $$ LANGUAGE SQL STRICT IMMUTABLE; COMMENT ON FUNCTION pg_schema_size(text) IS 'Returns the size for given schema name';