List tables that take up 50% of space in PostgreSQL database

Query below return table which uses 50% of summary space used by all database tables.

Query

select schemaname as table_schema, 
       relname as table_name,
       pg_size_pretty(pg_relation_size(relid))
from pg_catalog.pg_statio_user_tables
where pg_relation_size(relid) > 0.5 * (
        select sum((pg_relation_size(relid)))
        from pg_catalog.pg_statio_user_tables);

Columns

  • table_schema - name of schema
  • table_name - name of table
  • data_size - space used by table

Rows

  • Query should return one row

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.