How to list all databases and their schemas in postgresql? -
i looking way list databases , schemas on opensuse postgresql server. know can use meta commands such \l+
list of databases, there way list information databases including databases, schema , size information?
i'd way @ overall.
thanks!
i don't see way list of databases's schemas without connecting first. based on this, think can using db_link like:
create or replace function databases_schemas_size () returns setof record $body$ declare connection_info character varying; record; r record; begin r in select cast(datname character varying) pg_database datistemplate = false loop select format ('dbname=%s user=%s password=%s', r.datname, 'your_allowed_username', 'password') connection_info; perform dblink_connect(connection_info); in select r.datname, * dblink('select nspname , pg_size_pretty(sum(pg_relation_size(c.oid))) size pg_class c left join pg_namespace n on (n.oid = c.relnamespace) nspname not in (''pg_catalog'', ''information_schema'') group nspname') t(schema_name character varying, schema_size text) loop return next i; end loop; perform dblink_disconnect(); end loop; return; end; $body$ language plpgsql volatile cost 100; select * databases_schemas_size() (datname character varying, schema_name character varying, schema_size text);
you can improve not hard code login/password using foreign data wrapper functionality
Comments
Post a Comment