DBDiskSpaceManagement

From GombeMIWiki
Jump to: navigation, search

DB Disk Space Management

The queries on this page must be run by an administrative login to get a complete picture of disk usage. When run by a regular user the queries will show only the portion of the database to which the user has access.

Note that the database uses space not shown in these queries. These queries are useful in determining relative disk usage. Actual disk usage may vary somewhat.

It may be desirable to modify these queries to change the sort order or limit the results returned.

Disk Space by Schema (by User)

Use the following query to discover how much space is used per-schema.

-- Space used by schema (which user is using space)
select pg_namespace.nspname as schema
      , pg_size_pretty(sum(pg_total_relation_size(pg_class.oid)))
        as size
   from pg_class, pg_namespace
   where pg_class.relnamespace = pg_namespace.oid
   group by pg_namespace.nspname
   order by sum(pg_total_relation_size(pg_class.oid)) desc;

Disk Space Used by Table

Use the following query to discover how much space is used per-table.

-- Space used by schema (which user is using space)
select pg_namespace.nspname as schema
      , pg_class.relname as table
      , pg_size_pretty(pg_total_relation_size(pg_class.oid)) 
        as size
   from pg_class, pg_namespace
   where pg_class.relnamespace = pg_namespace.oid
   order by pg_total_relation_size(pg_class.oid) desc;