您好,登錄后才能下訂單哦!
小編給大家分享一下PostgreSQL查詢每個表大小的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
PostgreSQL如何查詢每個表的大小
1、查詢數據庫中單個表的大小(不包含索引)
select pg_size_pretty(pg_relation_size('表名'));
2、查詢所有表的大小并排序(包含索引)
推薦:postgresql教程
SELECT table_schema || '.' || table_name AS table_full_name, pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS size FROM information_schema.tables ORDER BY pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC limit 20
3、查詢表大小按大小排序并分離data與index
SELECT table_name, pg_size_pretty(table_size) AS table_size, pg_size_pretty(indexes_size) AS indexes_size, pg_size_pretty(total_size) AS total_size FROM ( SELECT table_name, pg_table_size(table_name) AS table_size, pg_indexes_size(table_name) AS indexes_size, pg_total_relation_size(table_name) AS total_size FROM ( SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name FROM information_schema.tables ) AS all_tables ORDER BY total_size DESC ) AS pretty_sizes
看完了這篇文章,相信你對PostgreSQL查詢每個表大小的方法有了一定的了解,想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。