How do you find the disk size of a Postgres / PostgreSQL table and its indexes

前端 未结 9 2167
甜味超标
甜味超标 2020-12-02 03:42

I\'m coming to Postgres from Oracle and looking for a way to find the table and index size in terms of bytes/MB/GB/etc, or even better the size for all tables.

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 04:23

    The Query below will serve you

    SELECT nspname || '.' || relname AS "relation",
      pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
    FROM pg_class C
    LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
    WHERE nspname NOT IN ('pg_catalog', 'information_schema')
      AND C.relkind <> 'i'
      AND nspname !~ '^pg_toast'
    ORDER BY pg_total_relation_size(C.oid) DESC
    LIMIT 20;
    

    See this Link: https://wiki.postgresql.org/wiki/Disk_Usage

提交回复
热议问题