til icon indicating copy to clipboard operation
til copied to clipboard

Check size table in postgres

Open xluffy opened this issue 7 years ago • 0 comments

SELECT
   relname as "table",
   pg_size_pretty(pg_relation_size(relid)) AS tb_size,
   pg_size_pretty(pg_total_relation_size(relid)) As "total_size",
   pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "idx_size"
   FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC LIMIT 10;
  • table – The name of the table
  • tb_size - The size of table
  • total_size – The total size that this table takes (table size + index size)
  • idx_size – The size that related objects of this table like indices take
SELECT n.nspname AS table_schema,
       c.relname AS table_name,
       c.reltuples::int AS rows
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'r'
      AND n.nspname NOT IN ('information_schema','pg_catalog')
ORDER BY c.reltuples DESC LIMIT 10;

xluffy avatar Jan 05 '18 06:01 xluffy