0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PostgreSQLでテーブルごとのサイズ情報などを得る

Posted at

ある日、データ転送の依頼があり、現状のPostgreSQLのテーブルごとの大体のサイズなどを知りたいことがあったので、調べたメモ。

確認環境

PostgreSQL 12系

SQL

SELECT
    relname as table_name,
    (select count(column_name) from information_schema.columns c where c.table_name = pg.relname and c.table_schema = 'public') as column_count,
    reltuples as rows,
    pg_size_pretty(relpages::bigint * 8 * 1024) as size,
    pg_size_pretty(cast(case reltuples when 0 then 0 else relpages::bigint * 8192 / reltuples end as bigint)) as average_row_size
FROM pg_class pg,
     pg_namespace pgn
WHERE pg.relnamespace = pgn.oid
  AND pgn.nspname = 'public'
  AND relkind = 'r'
ORDER BY relname ASC;

reltuplesやrelpagesは推定のサイズであるが、ある程度のサイズ感が分かればよかったのでこれで。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?