Last active
January 28, 2016 02:49
-
-
Save tadyjp/500a4820a33b4db33378 to your computer and use it in GitHub Desktop.
PostgreSQLでテーブルのレコード数とテーブルサイズを計算する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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