DBA/Postgresql

테이블별 사이즈

da-dba 2024. 4. 4. 14:51
SELECT *, pg_size_pretty(total_bytes) AS total
    , pg_size_pretty(index_bytes) AS INDEX
    , pg_size_pretty(toast_bytes) AS toast
    , pg_size_pretty(table_bytes) AS TABLE
  FROM (
  SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
      SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
              , c.reltuples AS row_estimate
              , pg_total_relation_size(c.oid) AS total_bytes
              , pg_indexes_size(c.oid) AS index_bytes
              , pg_total_relation_size(reltoastrelid) AS toast_bytes
          FROM pg_class c
          LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
          WHERE relkind = 'r'
  ) a
) a where table_name not like 'pt_%'

'DBA > Postgresql' 카테고리의 다른 글

로그 테이블(감사)  (0) 2024.04.04
파티션테이블 관련 데이터 사이즈 조회 및 스키마 변경  (0) 2024.04.04
DB CREATE 및 DROP  (0) 2024.04.04
psql 명령어  (0) 2024.04.04
서비스 유저 생성  (0) 2024.04.04