Postgres: Table list ordered by row count

  select nspname as schema, relname as tablename, 

   to_char(reltuples, '999,999,990') as row_count

  from pg_class c JOIN pg_catalog.pg_namespace n

   ON n.oid = c.relnamespace where relkind='r'

    order by reltuples desc



SELECT psu.schemaname as "schema", psu.relname AS table_name

    , to_char(sum(pg_total_relation_size(psu.relid)), '999,999,999,990') AS include_ndx

    , to_char(sum(pg_table_size(psu.relid)), '999,999,999,990') as whole_table

    , to_char(sum(pg_relation_size(psu.relid)), '99,999,999,990') AS not_toasts

    , to_char(sum(pg_table_size(psu.relid) - pg_relation_size(psu.relid)), '999,999,999,990') AS toasts

    , to_char(sum(pg_indexes_size(psu.relid)), '99,999,999,990') AS indexes

    , to_char(cl.reltuples, '999,999,990') as row_count

FROM pg_catalog.pg_statio_user_tables psu

    , pg_catalog.pg_class cl

where psu.relid = cl.oid

group by psu.schemaname, psu.relname, cl.reltuples

order by 1

;

Comments

Popular posts from this blog

Oracle: To clean up WRI$_ADV_OBJECTS