PostgreSQLでテーブルごとの行数(概算)を表示

MySQLでいうshow table statusのようなことがしたいときがよくあるのでメモ。

select c.relname, c.reltuples
from pg_class c
inner join pg_tables t on c.relname = t.tablename
where t.schemaname = 'public'
order by c.relname;

追加で t.tablename like でテーブル名をしぼりこめる。

show table statusと同じく概算であり、正確な行数をあらわしてないことに注意が必要。

2022/01/13追記

詳しく書いてある PostgreSQLのテーブルサイズの調べ方 - RAKUS Developers Blog | ラクス エンジニアブログ https://tech-blog.rakus.co.jp/entry/20190918/postgresql