Skip to content

Instantly share code, notes, and snippets.

@tadyjp
Last active January 28, 2016 02:49
Show Gist options
  • Save tadyjp/500a4820a33b4db33378 to your computer and use it in GitHub Desktop.
Save tadyjp/500a4820a33b4db33378 to your computer and use it in GitHub Desktop.
PostgreSQLでテーブルのレコード数とテーブルサイズを計算する
SELECT a.table_name, pg_relation_size(a.table_name) AS size, b.count FROM information_schema.tables AS a
INNER JOIN (
SELECT relname, n_tup_ins - n_tup_del as count FROM pg_stat_all_tables
) AS b
ON b.relname = a.table_name
WHERE a.table_schema = 'public'
ORDER BY size DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment